python得到文件版本信息,公司名和产品名2


为什么还有二,因为一使用了win32api模块,而这个模块只在windows系统下有,对linux系统木有这个模块。。
在linux下得到文件 版本信息是通过pefile模块解析文件 中的字符串得到的。。。
代码:
[python]
#---------------------------------------------------------------------- 
    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) 

我只要了公司名称信息和产品名称信息。。至于版本号之类的信息也是在字符串资源中。。。。

 


摘自 小驹的专栏

相关内容

    暂无相关文章

评论关闭