Advertisement

Windows Python 获取文件版本信息(非WinAPI 32位方式)

阅读量:

由于公司内部环境限制,无法安装winapi32模块,因此尝试通过Windows命令行工具获取文件版本信息,具体实现代码如下:

复制代码
    import subprocess
    import os
    
    # 通过bat命令行 获取内容然后get到
    def getFileVersion(filePath):
    if(not os.path.exists(filePath)):
        print('file not exist')
    filePath = filePath.replace('\ ', '\ \ ')
    print(filePath)
    cmd = 'wmic datafile where ' + '\"name=\'' + filePath + '\'\"' + ' get Version /format:list'
    print(cmd)
    p = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    out=p.stdout.readlines()
    
    for line in out:
        if(str(line.strip()).find('Versio

全部评论 (0)

还没有任何评论哟~