[Python] Get more information about the win platform file

Source: Internet
Author: User
Tags 04x

Import Win32apidef getfileproperties (fname): "" reads all properties of the given file, returning a dictionary.        "" "Propnames = (' Comments ', ' InternalName ', ' ProductName ', ' CompanyName ', ' legalcopyright ', ' productversion ', ' FileDescription ', ' legaltrademarks ', ' privatebuild ', ' fileversion ', ' originalfilename ', ' specialbuild ') p Rops = {' Fixedfileinfo ': None, ' stringfileinfo ': None, ' FileVersion ': none} try:fixedinfo = Win32API. GetFileVersionInfo (fname, ' \ \ ') props[' fixedfileinfo '] = fixedinfo props[' fileversion '] = "%d.%d.%d.%d"% (f                ixedinfo[' 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 first pair. Lang, codepage = Win32API.       GetFileVersionInfo (fname, ' \\VarFileInfo\\Translation ') [0] # Any other must is of the form \stringfileinfo\%04x%04x\parm_name, Middle # and is Language/codepage pair return ed from above Strinfo = {} to propname in Propnames:strinfopath = U ' \\StringFileInfo\\%04X%04X\ \%s '% (lang, codepage, propname) # # print Str_info strinfo[propname] = Win32API. GetFileVersionInfo (fname, Strinfopath) props[' stringfileinfo '] = Strinfo Except:pass return propsif _ _name__ = "__main__": getfileproperties (./python.exe)

  

https://stackoverflow.com/a/7993095/2615376

View Python.exe return:

>>> pprint (getfileproperties (path)) {' FileVersion ': ' 3.6.2150.1013 ', ' fixedfileinfo ': {' filedate ': None, ' FileFlags ': 0, ' fileflagsmask ':, ' Fileos ': 4, ' filesubt  Ype ': 0, ' FileType ': 1, ' fileversionls ': 140903413, ' Fileversionms ':                   196614, ' productversionls ': 140903413, ' productversionms ': 196614,                    ' Signature ': -17890115, ' strucversion ': 65536}, ' Stringfileinfo ': {' Comments ': None, ' CompanyName ': ' Python software Foundation ', ' filedescription ': ' Python ', ' Fileversi On ': ' 3.6.2 ', ' internalname ': ' Python Console ', ' legalcopyright ': ' Copyright? 2001-2016 Python Software ' Foundation. Copyright? "Beopen.com". CopyRight? 1995-2001 Cnri. "The Copyright?"                    1991-1995 SMC. ', ' legaltrademarks ': None, ' originalfilename ': ' Python.exe ',                     ' Privatebuild ': None, ' ProductName ': ' Python ', ' productversion ': ' 3.6.2 ', ' Specialbuild ': none}}>>>

  

[Python] Get more information about the win platform file

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.