Python obtains the file version information, company name, and product name in Linux,
This article describes how to obtain the file version information, company name, and product name in Linux using python. 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.