This article is an example of how Python obtains file version information, company name and product name, and share it for everyone's reference. Specifically as follows:
The Python code can get file version information, company name, and product name. The rest of the information is in the returned dictionary. The specific code is as follows:
def _getcompanynameandproductname (self, File_path): "" "Read all properties of the given file return them as
A dictionary.
"" "Propnames = (' Comments ', ' InternalName ', ' ProductName ', ' CompanyName ', ' legalcopyright ', ' productversion ',
' FileDescription ', ' legaltrademarks ', ' privatebuild ', ' fileversion ', ' originalfilename ', ' specialbuild ' Props = {' Fixedfileinfo ': None, ' stringfileinfo ': None, ' FileVersion ': none} try: # backslash as PA RM returns dictionary of numeric info corresponding to Vs_fixedfileinfo struc = Fixedinfo. GetFileVersionInfo (file_path, ' \ \ ') props[' fixedfileinfo '] = fixedinfo props[' fileversion '] = "%d.%d.%d.%d"
% (fixedinfo[' 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 the ' the ' the ' the '. Lang, codepage = Win32API. GetFileVersionInfo (File_path, ' \\VarFileInfo\\Translation ') [0] # Any other must is of the form \stringfileinfo\ %04x%04x\parm_name, Middle # Two are language/codepage pair returned from above Strinfo = {} for PropName in Propnames:strinfopath = U ' \\StringFileInfo\\%04X%04X\\%s '% (lang, codepage, propname) # # P Rint str_info Strinfo[propname] = Win32API. GetFileVersionInfo (File_path, Strinfopath) props[' stringfileinfo '] = Strinfo except:pass if n OT props["Stringfileinfo"]: return (none, none) Else:return (props["Stringfileinfo"] ["Companname"], PR
ops["Stringfileinfo" ["ProductName"])
I hope this article will help you with your Python programming.