Windows File Version Comparison....

emuller at painewebber.com emuller at painewebber.com
Sat Nov 13 14:11:12 EST 1999


I wrote a def that gets the file version of a windows exe/dll/cpl type
of file. It relies on filever.exe (part of the NT reskit) to be
available, but it should work for anyone looking to do this until the
win32ver module is finished. If you are looking for this module, it is
was under a '.dll and .exe version ...' thread. Anyway...

Once I did that, I could get the version of the file back, the next
thing I had to do was compare two versions and see which one was newer.
Since version strings can be '4.0.1.123'. I couldn't just convert them
to a float, and python thought that '4.0.1.6' was greater
than '4.0.1.42' for soem reason. So I wrote the following def to check
two version strings and return true/false....here it is...If anyone has
any problems with it, let me know, if anyone uses it let me know, if
anyone fixes a bug in it, let me know....

def compVer(ver1,ver2):
    #Checks to see if ver1 >= ver2
    import string
    vl1 = string.split(ver1,'.')
    vl2 = string.split(ver2,'.')
    while 1:
        if int(vl1[0]) > int(vl2[0]):
            return 1
        elif int(vl1[0]) == int(vl2[0]):
            del vl1[0]
            del vl2[0]
            if len(vl1) >= 1 and len(vl2) == 0:
                true = 1
                for each in vl1:
                    if int(each) <> 0:
                        true = 0
                return true
            elif len(vl1) == 0 and len(vl2) >= 1:
                true = 1
                for each in vl2:
                    if int(each) <> 0:
                        true = 0
                return true
            elif len(vl1) == 0 and len(vl2) == 0:
                return 1
            else:
                continue
        elif int(vl1[0]) < int(vl2[0]):
            return 0


Sent via Deja.com http://www.deja.com/
Before you buy.




More information about the Python-list mailing list