engjcowi Posted April 15, 2008 Posted April 15, 2008 I need a simple script in autoit that can open two text files and compare numbers withing them and decide which one is bigger for an update program im creating.ThanksJamie
MHz Posted April 18, 2008 Posted April 18, 2008 Some use this method. This will work so long as the versions are not padded with leading zeros.If Not FileExists('file1.txt') And Not FileExists('file2.txt') Then ; create test files If FileWrite('file1.txt', '2.1.1.0') And FileWrite('file2.txt', '1.1.1.0') Then ConsoleWrite('Test files written' & @CRLF) EndIf ; Read test files and compare versions $file1 = StringStripWS(FileRead('file1.txt'), 3) $file2 = StringStripWS(FileRead('file2.txt'), 3) If $file1 > $file2 Then MsgBox(0x40000, '', $file1 & ' > ' & $file2 & @CRLF) EndIf ; remove test files If FileDelete('file1.txt') And FileDelete('file2.txt') Then ConsoleWrite('Test files removed' & @CRLF) EndIfEndIfTo have a more thorough method then use StringSplit to split the version into elements that can be compared numerically.If Not FileExists('file1.txt') And Not FileExists('file2.txt') Then ; create test files If FileWrite('file1.txt', '2.1.1.0') And FileWrite('file2.txt', '2.2.1.0') Then ConsoleWrite('Test files written' & @CRLF) EndIf ; Read test files and compare versions $file1 = FileRead('file1.txt') $file2 = FileRead('file2.txt') If _HigherVersion($file1, $file2) And Not @error Then MsgBox(0x40000, '', 'Higher version') ElseIf @error Then MsgBox(0x40000, 'Error', @error) EndIf ; remove test files If FileDelete('file1.txt') And FileDelete('file2.txt') Then ConsoleWrite('Test files removed' & @CRLF) EndIfEndIfFunc _HigherVersion($current, $update) $current = StringSplit($current, '.') If @error Then Return SetError(1, 0, '') $update = StringSplit($update, '.') If @error Then Return SetError(1, 0, '') If $current[0] <> $update[0] Then Return SetError(2, 0, '') For $i = 1 To $current[0] If Int($current[$i]) = Int($update[$i]) Then ContinueLoop ElseIf Int($current[$i]) < Int($update[$i]) Then Return True EndIf NextEndFunc
Yzöwl Posted April 18, 2008 Posted April 18, 2008 Thanks for taking this one MHz, we don't see much of you these days especially in the programming forum!
engjcowi Posted April 19, 2008 Author Posted April 19, 2008 Those are both fantastic thank you very much.They have helped me alot. i hope to release a program soon because of your help
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now