Python脚本遍历文件夹,检查文件版本是否存在
Python脚本遍历文件夹,检查文件版本是否存在
from win32api import GetFileVersionInfo, LOWORD, HIWORD import os import fnmatch 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 def main(): path=r"C:\Program Files (x86)\" for root, dir, files in os.walk(path): files = fnmatch.filter(files, "*.exe") + fnmatch.filter(files, "*.dll") for item in files: version = get_version_number(os.path.join(root, item)) if version == (0,0,0,0): print(item) if __name__ == '__main__': main()
参考链接:
Python 3.6 install win32api? - Stack Overflow
python - How to access a file's properties on Windows? - Stack Overflow