meetrix Posted May 12, 2006 Share Posted May 12, 2006 I need some help. If I have a file that is 5K, how can I set this value. And if the value is less than 5K to error and stop. This is what I have so far... let me know. Any help would be appreciated. $size = FileGetSize("c:\customerlogs\0007854963214578.log") If $size = <> 1-5 Then MsgBox (0, "Error", "File size is incorrect!") Else MsgBox (0,"Results", $size) EndIf Link to comment Share on other sites More sharing options...
Lapo Posted May 12, 2006 Share Posted May 12, 2006 (edited) $size = FileGetSize("test.txt") MsgBox(262144, "", $size) If $size < 5000 Then MsgBox (0, "Error", "File size is incorrect!") Else MsgBox (0,"Results", $size) EndIf Edited May 12, 2006 by Lapo Link to comment Share on other sites More sharing options...
CyberSlug Posted May 12, 2006 Share Posted May 12, 2006 ;note that FileGetSize returns a result in bytes If Round($size/1024) <> 5 Then Exit Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
meetrix Posted May 14, 2006 Author Share Posted May 14, 2006 Thanks guys for the help. I did reliaze that the logs sizes varied. I thought that this would be the best way to find out if the log file is good (Passed) or bad (Failed). So, I'm now forced to take a different approach. I will have to read the line or search for the text withing the file. Does anyone have any ideas? This is what I have to far: Total pass: 24 is the line I need to search. Then provide options what do if found or not found. Some how this script keeps looping???? I have attached the text file. $file = FileOpen("0173032006000041.txt", 0) $var = EnvSet("Passed", "Total Pass:15") If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($file,15) If @error = -1 Then ExitLoop MsgBox(0, "Line read:", $line) If $var Then MsgBox(0, "Passed:", "Test Results are Good, Ready to Print") EndIf Wend FileClose($file) $size = FileGetSize("test.txt") MsgBox(262144, "", $size) If $size < 5000 Then MsgBox (0, "Error", "File size is incorrect!") Else MsgBox (0,"Results", $size) EndIf0173032006000041.txt Link to comment Share on other sites More sharing options...
Lapo Posted May 15, 2006 Share Posted May 15, 2006 ; my test file test.txt on line 1 = EnvSet("Passed", "Total Pass:15") ; launch the script ando open test.txt and put EnvSet("Passed", "Total Pass:15") ; on line 1 and save test.txt $file = FileOpen("test.txt", 0) $var = EnvSet("Passed", "Total Pass:15") If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 ; $line = FileReadLine($file,15) $line = FileReadLine($file,1) sleep(100) If @error = -1 Then ExitLoop ; MsgBox(0, "Line read:", $line) If StringInStr($line, "Passed") then MsgBox(0, "Passed:", "Test Results are Good, Ready to Print") exit EndIf Wend FileClose($file) Link to comment Share on other sites More sharing options...
Lapo Posted May 15, 2006 Share Posted May 15, 2006 tested on your file : $file = FileOpen("0173032006000041.txt", 0) ;$var = EnvSet("Passed", "Total Pass:15") If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($file,15) ;MsgBox(262144, "", $line) ; $line = FileReadLine($file,1) sleep(100) If @error = -1 Then ExitLoop ; MsgBox(0, "Line read:", $line) If StringInStr($line, "24") then MsgBox(0, "Passed:", "Test Results are Good, Ready to Print") exit EndIf Wend FileClose($file) Link to comment Share on other sites More sharing options...
meetrix Posted May 15, 2006 Author Share Posted May 15, 2006 Thanks for your feedback. I will try your script. I did find something that you may want to try. $Passed = "Total Pass: 24" $LogFile = FileOpen($v_path&$s_serial&".log",0) If $LogFile = -1 Then MsgBox(0x10, "Fatal Error, File Does Not Exist", "Need to Run ETS Testing") Exit EndIf ;------------------------------------------ ; Printing Report from Server Drive U:\ ;------------------------------------------ $i = 1 While 1 $Read = FileReadLine($LogFile, $i) If @error Then ExitLoop If StringInStr($Read, $Passed) Then ;;;; What ever you need done at this point. tested on your file : $file = FileOpen("0173032006000041.txt", 0) ;$var = EnvSet("Passed", "Total Pass:15") If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($file,15) ;MsgBox(262144, "", $line) ; $line = FileReadLine($file,1) sleep(100) If @error = -1 Then ExitLoop ; MsgBox(0, "Line read:", $line) If StringInStr($line, "24") then MsgBox(0, "Passed:", "Test Results are Good, Ready to Print") exit EndIf Wend FileClose($file) Link to comment Share on other sites More sharing options...
Lapo Posted May 16, 2006 Share Posted May 16, 2006 look at the help file >> C:\PROGRA~1\AUTOIT3\AUTOIT3.CHM But WATCH on your $var ERROR : $file = FileOpen("0173032006000041.txt", 0) ;$var = "Total Pass: 24" ; $var = " Total Pass: 24" ; WATCH the space at BEGINNING If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ; MsgBox(0, "Line read:", $line) If StringInStr($line, $var) Then MsgBox(262144, "", "bingo") endif Wend FileClose($file) Link to comment Share on other sites More sharing options...
Lapo Posted May 16, 2006 Share Posted May 16, 2006 (edited) I have not time to test it now .. but here a starting point this if $Passed = " Total Pass: 24" is true exit the script else it continues the loop expandcollapse popup; EDIT ;$Passed = " Total Pass: 24" ; NO $Passed = " Total Pass: 24" ; YES $LogFile = FileOpen("0173032006000041.txt",0) If $LogFile = -1 Then MsgBox(0x10, "Fatal Error, File Does Not Exist", "Need to Run ETS Testing") Exit EndIf ;------------------------------------------ ; Printing Report from Server Drive U:\ ;------------------------------------------ #CS For $i = 1 to 50 $Read = FileReadLine($LogFile, $i) MsgBox(262144, "", $read) If @error Then ExitLoop If StringInStr($Read, $Passed) Then MsgBox(262144, "", "bingo") exit ;;;; What ever you need done at this point. EndIf next #ce While 1;use infinite loop since ExitLoop will get called $Read = FileRead($LogFile) ;MsgBox(262144, "", $read) ;If @error Then ExitLoop If StringInStr($Read, $Passed) Then ; $Read = FileRead($LogFile) MsgBox(262144, "", "bingo") ExitLoop else MsgBox(262144, "", "no") EndIf ;exit ;;;; What ever you need done at this point. WEnd ; EndIf Edited May 16, 2006 by Lapo Link to comment Share on other sites More sharing options...
Lapo Posted May 17, 2006 Share Posted May 17, 2006 (edited) the web page mess up the $Passed variable copy and paste " Total Pass: 24" directly from your txt/log file NOT from here ; EDIT ;$Passed = " Total Pass: 24" ; NO $Passed = " Total Pass: 24" ; YES test: $Passed = " Total Pass: 24" $Passed = " Total Pass: 24" Edited May 17, 2006 by Lapo Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted May 17, 2006 Moderators Share Posted May 17, 2006 You could probably lighten that up a bit, and help with some preventative maintenance:$Passed = "Total Pass: 24" $LogFile = "0173032006000041.txt" While 1 If StringInStr(StringStripWS(FileRead($LogFile, FileGetSize($LogFile)), 7), $Passed) Then MsgBox(262144, "", "bingo") ExitLoop Else MsgBox(262144, "", "no") EndIf WEndThis worked on my test. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Lapo Posted May 17, 2006 Share Posted May 17, 2006 You could probably lighten that up a bit, and help with some preventative maintenance:$Passed = "Total Pass: 24" $LogFile = "0173032006000041.txt" While 1 If StringInStr(StringStripWS(FileRead($LogFile, FileGetSize($LogFile)), 7), $Passed) Then MsgBox(262144, "", "bingo") ExitLoop Else MsgBox(262144, "", "no") EndIf WEndThis worked on my test. Yes .. worked here too .. cleaner script also ... but STRANGE behaviour with spaces here 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