polkamatador Posted August 20, 2006 Share Posted August 20, 2006 Hi, I've got a Problem with the Inetget function: I have a files.txt on my webserver which contains the word "test" in a random line between 1 and 1000. Now my script should check every time the function check is called if the word "test" is still in the file.txt. If it's in the file.txt it should continue, if "test" is missing exit the programm. Problem: AutoIt checks the file.txt and says it contains "test" what is correct :=) but when I delete the "start" word on my webservers file.txt auto it still says that the file.txt contains the word "test" , but I deleted it... and it's 100% not anymore in the file.txt so it seems to me, that autoit download's the file.txt once with the "start" word inside, and doesn't create it new for each func check() . expandcollapse popupfunc check() InetGet("http://myserver.de/file.txt", @TempDir & "\file.txt") $files= FileOpen(@TempDir & "\file.txt", 0) $test = "test" Local $h=1 While 1 $reader= FileReadLine($files, $h) If $reader = - 1 Then $h = 1000 EndIf If $test = $reader Then MsgBox(4096,"Found in files.txt ","",0) ExitLoop EndIf $h = $h + 1 If $h = 1000 Then If $test <> $reader or $reader = -1 Then MsgBox(4096,"missing test in files.txt!!! ","",0) Exit EndIf EndIf WEnd FileClose($files) FileDelete(@ScriptDir & "\file.txt") Endfunc Would be nice to receive help Thx Link to comment Share on other sites More sharing options...
azeazezar Posted August 20, 2006 Share Posted August 20, 2006 (edited) func check() InetGet("http://myserver.de/file.txt", @TempDir & "\file.txt", 1);<<---changed $files= FileOpen(@TempDir & "\file.txt", 0) $test = "test" Local $h=1 While 1 $reader= FileReadLine($files, $h) If $reader = - 1 Then $h = 1000 EndIf If $test = $reader Then MsgBox(4096,"Found in files.txt ","",0) ExitLoop EndIf $h = $h + 1 If $h = 1000 Then If $test <> $reader or $reader = -1 Then MsgBox(4096,"missing test in files.txt!!! ","",0) Exit EndIf EndIf WEnd FileClose($files) FileDelete(@TempDir & "\file.txt");<<-- you wheredeleting something you didn't make, corrected Endfunc Try this ^^ Edited August 20, 2006 by azeazezar Link to comment Share on other sites More sharing options...
polkamatador Posted August 20, 2006 Author Share Posted August 20, 2006 Omg... Thx you saved my day I tryed to fix that the whole day.... Link to comment Share on other sites More sharing options...
Valuater Posted August 20, 2006 Share Posted August 20, 2006 i would do it more like this... ( without $h also ) Func check() Local $h = 0 Local $test = "test" Local $file = @TempDir & "\file.txt" InetGet("http://myserver.de/file.txt", $file, 1) $files = FileOpen($file, 0) While 1 $h = $h + 1 $reader = FileReadLine($files, $h) If @error = -1 Or $h = 1000 Then MsgBox(4096, "missing test in files.txt!!! ", "", 0) ExitLoop EndIf If StringInStr($reader, $test) Then MsgBox(4096, "Found in files.txt ", "", 0) ExitLoop EndIf WEnd FileClose($files) FileDelete($file) EndFunc ;==>check 8) Link to comment Share on other sites More sharing options...
MHz Posted August 20, 2006 Share Posted August 20, 2006 My suggestion Func check() Local $found, $file_handle, $reader, $test = "test" Local $file_download = @TempDir & "\file.txt" ; Download the file If InetGet("http://myserver.de/file.txt", $file_download, 1) Then ; Loop through each line to find "test" $file_handle = FileOpen($file_download, 0) If $file_handle <> -1 Then While 1 $reader = FileReadLine($file_handle) If @error Then ExitLoop ; Search for value of $test If $test = $reader Then $found = True ExitLoop EndIf WEnd FileClose($file_handle) ; Report the result If $found Then MsgBox(4096, @ScriptName, "Found in files.txt") Else MsgBox(4096, @ScriptName, "missing test in files.txt!!!") EndIf ; Cleanup FileDelete($file_download) Else MsgBox(4096, @ScriptName, "File to open failed") EndIf Else MsgBox(4096, @ScriptName, "Download failed") Return SetError 1 EndIf EndFunc This will find only the word "test" in a line of the file and nothing else. Also covers any failure to alert with MsgBox of problem to save any later debug headaches. Link to comment Share on other sites More sharing options...
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