[python-win32] Executable file version in windows
Martin Richard
Richard.Martin at thomson.net
Wed Feb 4 19:45:20 EST 2004
A hack that requires filever.exe from the NT resource kit. filever returns
a human readable output that the code reads via a pipe; then it gets
substrings and does pattern matches to get the appropriate information.
It depends on developers putting the version string in a location where
filever can get it.
Rick
def getFileVerInfo(fullFilePath, verbose=0):
'''
Uses FileVer to get file information.
Args:
fullFilePath: should be a path reachable from the current directory
Returns:
a tuple of strings for the value of the ProductVersion and the
value of FileVersion
'''
pipe = 0
inputLine = 'not blank'
productVersionPattern = re.compile("\W*ProductVersion\W*(\S*)", re.I)
fileVersionPattern = re.compile("\W*FileVersion\W*(\S*)", re.I)
noFileVerPattern = re.compile("not recognized", re.I)
dirPattern = re.compile('-----')
productVersionString = ''
fileVersionString = ''
if verbose:
print fullFilePath
try:
# need to quote the path name to handle filenames with spaces
pipe = os.popen ('.\\filever.exe /v "%s"' % fullFilePath)
# fileInfo will be a list of lines from the output of filever
fileInfo = pipe.readlines()
pipe.close()
except:
traceback.print_exc()
raise "Could not run filever. Make sure it is on your path"
# look for size and date from first line
try: fileDate = fileInfo[0][50:60]
except: fileDate = 'unknown'
try: fileSize = fileInfo[0][39:49]
except: fileSize = 'unknown'
# look for product and file version strings in the reminder of the
# output from filever.exe
for line in fileInfo[1:]:
match = productVersionPattern.search(line)
if match:
productVersionString = match.group(1)
match = fileVersionPattern.search(line)
if match:
fileVersionString = match.group(1)
return (fileDate, fileSize, productVersionString, fileVersionString)
-----Original Message-----
From: Michel Bélanger [mailto:michel.belanger at seidel.ca]
Sent: Wednesday, February 04, 2004 4:33 PM
To: python-win32 at python.org
Subject: [python-win32] Executable file version in windows
Hi,
How can I query a file executable (exe, dll, com)for its version
including the revision, i.e.
exemple:
>>>queryVersion("someprog.exe")
5.1.2
Many thanks
Michel Belanger
_______________________________________________
Python-win32 mailing list
Python-win32 at python.org http://mail.python.org/mailman/listinfo/python-win32
More information about the Python-win32
mailing list