Jump to content
Sign in to follow this  
quicksilver

Compare File Version Nr

Recommended Posts

quicksilver

Hi is there Any way to Compare 2 File Version Numbers?

$ver = FileGetVersion($path1)

$verakt = FileGetVersion($path2)

In the Variables $ver is something like This =

"2.6.2.244" or "2.6.2.245" or "2.7.0.000"

I want to compare $ver and $verakt..

if $ver higher.. then do this else do this...

Can Anyone Help me?

Share this post


Link to post
Share on other sites
PsaltyDS

Hi is there Any way to Compare 2 File Version Numbers?

$ver = FileGetVersion($path1)

$verakt = FileGetVersion($path2)

In the Variables $ver is something like This =

"2.6.2.244" or "2.6.2.245" or "2.7.0.000"

I want to compare $ver and $verakt..

if $ver higher.. then do this else do this...

Can Anyone Help me?

I ran into that with comparing current and available driver versions. My solution was to break both numbers into two arrays with StringSplit(FileGetVersion($path, "."), then looping through the arrays to compare one "part" at a time.

Another solution is to convert each part to a fixed format, like four digits with leading zeros using StringFormat, and assemble a single large number to compare, i.e. "If 0002000600020244 > 0002000700000000 Then"

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
ResNullius

Similar idea to PsaltyDS:

#include <math.au3>

$ver = "2.6.2.244" ; assume this is result from FileGetVersion($path1)
$verakt = "2.6.2.245" ; asume result from FileGetVersion($path2)

$ver = Ver2Num($ver)
$verakt = Ver2Num($verakt)

$maxVer = _Max($ver,$verakt)
MsgBox(0,"","The latest version is " & $maxVer )

Func Ver2Num($sVerNum)
    Local $aVerNum
    $aVerNum = StringSplit($sVerNum, ".")
    $sVerNum = $aVerNum[1] & "." 
    
    For $i = 2 To $aVerNum[0]
        $sVerNum &= $aVerNum[$i]
    Next

    Return Number($sVerNum)
EndFunc   ;==>Ver2Int

Now, lets wait for some StringRegExp expert show us how it really should be done :)

Share this post


Link to post
Share on other sites
NexusCommader

I know this is an old post but it pointed me in the right direction.

so I made this function to compare file sizes, I'm sharing this to help others out.

;=====
;script assumes no more than 3 decimal points 
;Created by NexusCommander

;Return:
;-1 = error
;0 = same version number
;1 = 1st version is bigger
;2 = 2nd version is bigger
;=====
Func Version_compare($ver1,$ver2)
    If $ver1 = '' OR $ver2 = '' Then Return -1
    $ver1 = StringSplit($ver1,'.')
    $ver2 = StringSplit($ver2,'.')
    ReDim $ver1[5]
    ReDim $ver2[5]
    For $a1 = 1 To 4
        Select
            Case Number($ver1[$a1]) = Number($ver2[$a1])
                ContinueLoop
            Case Number($ver1[$a1]) > Number($ver2[$a1])
                Return 1
            Case Number($ver1[$a1]) < Number($ver2[$a1])
                Return 2
        EndSelect
    Next
    Return 0
EndFunc

Share this post


Link to post
Share on other sites
smartee

hi,

Welcome to the forums NexusCommader ;)

This is a really old thread (~4yrs old :huh2: ) there is now an inbuilt function you might want to check out in the helpfile called _VersionCompare().

Happy coding :alien:

-smartee

Share this post


Link to post
Share on other sites
GEOSoft

That's not really a built in function. It's just a function in a UDF; a good function mind you.

There are a lot of ways of doing it and I usually take an easy route although it has no error checking

Func _FileCompareVersion($sVer1, $sVer2)
    If Number(StringReplace($sVer1, ".", "")) = Number(StringReplace($sVer1, ".", "")) Then
        Return 0
    ElseIf Number(StringReplace($sVer1, ".", "")) > Number(StringReplace($sVer1, ".", "")) Then
        Return 1
    EndIf
    Return -1
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
smartee

That's not really a built in function. It's just a function in a UDF; a good function mind you.

Yes, a function in a UDF thats "built in" to the standard AutoIt installation :huh2:

I didn't say it was a native function but you seemed to react as if I did ;)

Anyway, I can understand how using the term "built in" that loosely can result in confusion.

Regards,

-smartee

Share this post


Link to post
Share on other sites
GEOSoft

I just try to be carefull with it. In this case it was a Dev that wrote the function but that isn't always the case and I'm sure there are many UDFs included that the Devs have never been involved in or may have never even read and yet they get the "Why doesn' _Function() work?" and they have to deal with the bug reports as well.

In the meantime you are correct that I read "built in" as "AutoIt native" or "AutoIt core".

There are several broken functions in those UDFs as a matter of fact but since they are UDFs I don't worry about it, just either re-write it or work around it myself.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×