Python ways to get File version information, company name, and product name _python

Source: Internet
Author: User
Tags 04x

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.