How to obtain file version information, company name, and product name in Linux using python

Source: Internet
Author: User
This article describes how to obtain file version information, company name, and product name in Linux using python, and describes how to use the pefile module, for more information about how to obtain file version information, company name, and product name in Linux, see the example in this article. The details are as follows:

It is different from the previous one. In this example, the file version information is obtained in linux, mainly obtained by parsing the strings in the file through the pefile module. The code is as follows:

  def _get_company_and_product(self, file_path):     """     Read all properties of the given file return them as a dictionary.     @return: a tumple, (company, product)     """     mype = pefile.PE(file_path)     companyName = ""     productName = ""           if hasattr(mype, 'VS_VERSIONINFO'):       if hasattr(mype, 'FileInfo'):         for entry in mype.FileInfo:           if hasattr(entry, 'StringTable'):             for st in entry.StringTable:               for k, v in st.entries.items():                 if k == u"CompanyName":                   companyName = v                 elif k == u"ProductName":                   productName = v     if not companyName:       companyName = None     if not productName:       productName = None     return (companyName, productName) 

Here we only need the company name and product name information. Information such as the version number is also in the string resource.

I hope this article will help you with Python programming.

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.