Import Win32apidef getfileproperties (fname): "" reads all properties of the given file, returning a dictionary. "" "Propnames = (' Comments ', ' InternalName ', ' ProductName ', ' CompanyName ', ' legalcopyright ', ' productversion ', ' FileDescription ', ' legaltrademarks ', ' privatebuild ', ' fileversion ', ' originalfilename ', ' specialbuild ') p Rops = {' Fixedfileinfo ': None, ' stringfileinfo ': None, ' FileVersion ': none} try:fixedinfo = Win32API. GetFileVersionInfo (fname, ' \ \ ') props[' fixedfileinfo '] = fixedinfo props[' fileversion '] = "%d.%d.%d.%d"% (f ixedinfo[' Fileversionms '/65536, fixedinfo[' fileversionms ']% 65536, fixedinfo[' fileversionls ']/65536, fixedinfo[' fileversionls ']% 65536) # \varfileinfo\translation returns list of available (language, CODEPAGE) # pairs that can is used to retreive string info. We are using only the first pair. Lang, codepage = Win32API. GetFileVersionInfo (fname, ' \\VarFileInfo\\Translation ') [0] # Any other must is of the form \stringfileinfo\%04x%04x\parm_name, Middle # and is Language/codepage pair return ed from above Strinfo = {} to propname in Propnames:strinfopath = U ' \\StringFileInfo\\%04X%04X\ \%s '% (lang, codepage, propname) # # print Str_info strinfo[propname] = Win32API. GetFileVersionInfo (fname, Strinfopath) props[' stringfileinfo '] = Strinfo Except:pass return propsif _ _name__ = "__main__": getfileproperties (./python.exe)
https://stackoverflow.com/a/7993095/2615376
View Python.exe return:
>>> pprint (getfileproperties (path)) {' FileVersion ': ' 3.6.2150.1013 ', ' fixedfileinfo ': {' filedate ': None, ' FileFlags ': 0, ' fileflagsmask ':, ' Fileos ': 4, ' filesubt Ype ': 0, ' FileType ': 1, ' fileversionls ': 140903413, ' Fileversionms ': 196614, ' productversionls ': 140903413, ' productversionms ': 196614, ' Signature ': -17890115, ' strucversion ': 65536}, ' Stringfileinfo ': {' Comments ': None, ' CompanyName ': ' Python software Foundation ', ' filedescription ': ' Python ', ' Fileversi On ': ' 3.6.2 ', ' internalname ': ' Python Console ', ' legalcopyright ': ' Copyright? 2001-2016 Python Software ' Foundation. Copyright? "Beopen.com". CopyRight? 1995-2001 Cnri. "The Copyright?" 1991-1995 SMC. ', ' legaltrademarks ': None, ' originalfilename ': ' Python.exe ', ' Privatebuild ': None, ' ProductName ': ' Python ', ' productversion ': ' 3.6.2 ', ' Specialbuild ': none}}>>>
[Python] Get more information about the win platform file