MSFN Forum: Auto it help please please - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Auto it help please please Rate Topic: -----

#1 User is offline   engjcowi 

  • Newbie
  • Group: Members
  • Posts: 42
  • Joined: 05-April 05

Posted 15 April 2008 - 03:54 PM

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


#2 User is offline   MHz 

  • SendToA3X v1.7
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 1,634
  • Joined: 02-August 04

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.
 
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 User is online   Yzöwl 

  • Wise Owl
  • Group: Super Moderator
  • Posts: 4,117
  • Joined: 13-October 04
  • OS:Windows 7 x64

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 User is offline   engjcowi 

  • Newbie
  • Group: Members
  • Posts: 42
  • Joined: 05-April 05

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

:thumbup :thumbup

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy