Kenneth
Kenneth

Reputation: 31

How can I get information on a file's Properties>Details using python?

So far I was only successful on getting the version of the using this code.

from win32com.client import Dispatch    
ver_parser = Dispatch('Scripting.FileSystemObject')
info = ver_parser.GetFileVersion(path + "\\" + file)

Right now, all I know is the "GetFileVersion" and my IDE won't autocomplete to show me any other options to extra the other informations

Sample File Properties>Details:

enter image description here

Upvotes: 3

Views: 8348

Answers (3)

fuglede
fuglede

Reputation: 18201

You can use win32com.client.gencache.EnsureDispatch to generate Python code corresponding to the COM module. With this, you can use __dir__ to access the names of all methods (and chances are that your IDE uses __dir__ to auto-complete code so that you get that as well);

In [204]: from win32com.client.gencache import EnsureDispatch

In [205]: ver_parser = EnsureDispatch('Scripting.FileSystemObject')

In [210]: [a for a in ver_parser.__dir__() if '_' not in a]
Out[210]:
['CLSID',
 'BuildPath',
 'CopyFile',
 'CopyFolder',
 'CreateFolder',
 'CreateTextFile',
 'DeleteFile',
 'DeleteFolder',
 'DriveExists',
 'FileExists',
 'FolderExists',
 'GetAbsolutePathName',
 'GetBaseName',
 'GetDrive',
 'GetDriveName',
 'GetExtensionName',
 'GetFile',
 'GetFileName',
 'GetFileVersion',
 'GetFolder',
 'GetParentFolderName',
 'GetSpecialFolder',
 'GetStandardStream',
 'GetTempName',
 'MoveFile',
 'MoveFolder',
 'OpenTextFile']

Note that this only gets you the names of methods and not of properties (yet), but you can get those by hand:

In [213]: set(ver_parser._prop_map_get_).union(set(ver_parser._prop_map_put_))
Out[213]: {'Drives'}

Related Stack Overflow questions:

Upvotes: 0

chakradhar kasturi
chakradhar kasturi

Reputation: 689

I think you can use "Shell.Application" to get file meta information.Something like below replace folder name and file name.

from win32com.client import Dispatch
shell = Dispatch("Shell.Application")
_dict = {}
# enter directory where your file is located
ns = shell.NameSpace("D:\\Userfiles\\Downloads")
for i in ns.Items():
    # Check here with the specific filename
    if str(i) == "Test.png":
        for j in range(0,49):
            _dict[ns.GetDetailsOf(j,j)] = ns.GetDetailsOf(i,j)

print _dict

Upvotes: 1

BioGeek
BioGeek

Reputation: 22827

According to this site you need a COM browser to see which methods and properties are available.

For a very basic one, do:

from win32com.client import combrowse
combrowse.main()

Upvotes: 0

Related Questions