Python 获取文件版本信息

Python 获取文件版本信息

from win32api import GetFileVersionInfo, LOWORD, HIWORD

def get_version_number (filename):
try:
info = GetFileVersionInfo (filename, "\\")
ms = info['FileVersionMS']
ls = info['FileVersionLS']
return HIWORD (ms), LOWORD (ms), HIWORD (ls), LOWORD (ls)
except:
return 0,0,0,0

if __name__ == '__main__':
import os
filename = os.environ["COMSPEC"]
print ".".join ([str (i) for i in get_version_number (filename)])

参考:https://stackoverflow.com/questions/580924/how-to-access-a-files-properties-on-windows

posted @ 2022-06-06 16:15  余生以学  阅读(397)  评论(0编辑  收藏  举报