当前位置: 移动技术网 > IT编程>脚本编程>Python > python获取文件版本信息、公司名和产品名的方法

python获取文件版本信息、公司名和产品名的方法

2019年03月25日  | 移动技术网IT编程  | 我要评论

程真真爸爸是什么官,老友记英文字幕版,幼儿园开学寄语

本文实例讲述了python获取文件版本信息、公司名和产品名的方法,分享给大家供大家参考。具体如下:

该python代码可得到文件版本信息、公司名和产品名。其他的信息都在返回的字典中。具体代码如下:

  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 parm returns dictionary of numeric info corresponding to vs_fixedfileinfo struc 
      fixedinfo = win32api.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 be used to retreive string info. we are using only the first pair. 
      lang, codepage = win32api.getfileversioninfo(file_path, '\\varfileinfo\\translation')[0] 
   
      # any other must be 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) 
        ## print str_info 
        strinfo[propname] = win32api.getfileversioninfo(file_path, strinfopath) 
   
      props['stringfileinfo'] = strinfo 
    except: 
      pass 
    if not props["stringfileinfo"]: 
      return (none, none) 
    else: 
      return (props["stringfileinfo"]["companname"], props["stringfileinfo"]["productname"]) 

希望本文所述对大家的python程序设计有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网