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.
Thanks
Jamie
Page 1 of 1
Auto it help please please
#2
Posted 18 April 2008 - 06:42 AM
Some use this method. This will work so long as the versions are not padded with leading zeros.
To 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', '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)
EndIf
EndIf
To 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)
EndIf
EndIf
Func _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
Next
EndFunc
#3
Posted 18 April 2008 - 07:12 AM
Thanks for taking this one MHz, we don't see much of you these days especially in the programming forum!
#4
Posted 19 April 2008 - 06:30 AM
Those are both fantastic thank you very much.
They have helped me alot. i hope to release a program soon because of your help
They have helped me alot. i hope to release a program soon because of your help
- ← Need to get a list of AD users and their email addy?
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- Logon/Logoff script to update computer description with who logged on? →
Share this topic:
Page 1 of 1



Help
Back to top









