1
+ import win32api
2
+
3
+ def get_file_properties (fname ):
4
+ prop_names = ('Comments' , 'InternalName' , 'ProductName' ,
5
+ 'CompanyName' , 'LegalCopyright' , 'ProductVersion' ,
6
+ 'FileDescription' , 'LegalTrademarks' , 'PrivateBuild' ,
7
+ 'FileVersion' , 'OriginalFilename' , 'SpecialBuild' )
8
+
9
+ props = {'FixedFileInfo' : None , 'StringFileInfo' : None , 'FileVersion' : None , 'FileDescription' : None }
10
+
11
+ fixed_info = win32api .GetFileVersionInfo (fname , '\\ ' )
12
+ props ['FixedFileInfo' ] = fixed_info
13
+ props ['FileVersion' ] = "%d.%d.%d.%d" % (fixed_info ['FileVersionMS' ] / 65536 ,
14
+ fixed_info ['FileVersionMS' ] % 65536 ,
15
+ fixed_info ['FileVersionLS' ] / 65536 ,
16
+ fixed_info ['FileVersionLS' ] % 65536 )
17
+
18
+ # \VarFileInfo\Translation returns list of available (language, codepage)
19
+ # pairs that can be used to retreive string info. We are using only the first pair.
20
+ lang , codepage = win32api .GetFileVersionInfo (fname , '\\ VarFileInfo\\ Translation' )[0 ]
21
+
22
+ # any other must be of the form \StringfileInfo\%04X%04X\parm_name, middle
23
+ # two are language/codepage pair returned from above
24
+
25
+ str_info = {}
26
+ for propName in prop_names :
27
+ str_info_path = u'\\ StringFileInfo\\ %04X%04X\\ %s' % (lang , codepage , propName )
28
+ str_info [propName ] = win32api .GetFileVersionInfo (fname , str_info_path )
29
+
30
+ props ['StringFileInfo' ] = str_info
31
+ # except:
32
+ # pass
33
+
34
+ return props
0 commit comments