0

I would like to have a way to read metadata from files, (like album, or artist, or date modified) in Python 3.8

I tried a suggestion from StackOverflow; Reading metadata with Python

Output from Python terminal:

Specs: Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:10) [MSC v.1916 64 bit (AMD64)] on win32 (on Windows 10)

and I was running it from my Downloads folder.

Whelp!

>>> import win32com.client
>>> sh = win32com.client.gencache.EnsureDispatch('Shell.Application',0)
>>> ns = sh.NameSpace(r"directory")
>>> colnum = 0
>>> columns = []
>>> while True:
...     colname = ns.GetDetailsOf(None, colnum)
...     if not colname:
...             break
...     columns.append(colname)
...     colnum += 1
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
AttributeError: 'NoneType' object has no attribute 'GetDetailsOf'

I Googled the error message and got nothing about this exact problem.

Could someone help me get this code working or find an alternative to this method that works?

1 Answers1

0

I think you're passing directory as r"C:\\<path>"

if you want to use r'string' make sure you use only single backslash i.e. r'C:\folder' or you just use 'C:\\path"

import win32com.client
sh = win32com.client.gencache.EnsureDispatch('Shell.Application',0)
ns = sh.NameSpace("C:\\projects")
colnum = 0
columns = []

while True:
     colname = ns.GetDetailsOf(None, colnum)
     if not colname:
             break
     columns.append(colname)
     colnum += 1

print(colnum)
print(columns)

Output
--------
37
['Name', 'Size', 'Item type', 'Date modified', 'Date created', 'Date accessed', 'Attributes', 'Offline status', 'Availability', 'Perceived type', 'Owner', 'Kind', 'Date taken', 'Contributing artists', 'Album', 'Year', 'Genre', 'Conductors', 'Tags', 'Rating', 'Authors', 'Title', 'Subject', 'Categories', 'Comments', 'Copyright', '#', 'Length', 'Bit rate',
'Protected', 'Camera model', 'Dimensions', 'Camera maker', 'Company', 'File description', 'Masters keywords', 'Masters keywords']
astiktyagi
  • 26
  • 3