Eviltim Posted September 6, 2005 Posted September 6, 2005 is there a way to check the last line of a text document for a particular phrase?
herewasplato Posted September 7, 2005 Posted September 7, 2005 is there a way to check the last line of a text document for a particular phrase?<{POST_SNAPBACK}>$file = FileOpen("test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached $line = "" $line_temp = "" While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop Else $line_temp = $line EndIf ;MsgBox(0, "Line read:", $line) Wend FileClose($file) ;MsgBox(0, "Line read:", $line_temp)$line_temp should have the last line.Now go read about StringInStr in the help file... [size="1"][font="Arial"].[u].[/u][/font][/size]
Eviltim Posted September 7, 2005 Author Posted September 7, 2005 (edited) Yea that definetly worked but the last line of the file is always blank searching through the help file i found _FileCountLines...it returns the last line number without counting the final @LF#include <file.au3> $file = "C:\Temp\Command.txt" Do $i = _FileCountLines($file) $string = FileReadLine($file, $i) $string = StringTrimLeft($string, 8) sleep(5000) Until $string = "Close"now im looking for a way to search the string for the phrase instead of trimming the info from the left. EDIT: Oh, herewasplato, i got the pm. i dont mind at all, thanks for all your help. Edited September 7, 2005 by Eviltim
Valuater Posted September 7, 2005 Posted September 7, 2005 Plato told you howNow go read about StringInStr in the help file...<{POST_SNAPBACK}>8)
herewasplato Posted September 7, 2005 Posted September 7, 2005 Plato told you how8)<{POST_SNAPBACK}>oh I did several stupid things:posted untested codelater thought of a problem with that codewent to correct the codenoticed the Eviltim was reading my bad codedeleted my post - but probably too late and wasted Eviltim's timehastely added the $line_temp = $line stuffposted what you see above(my original code only used $line which ends in EOF?)@Eviltim,as my penance, try this:#include <file.au3> $file = "C:\Temp\Command.txt" While 1 $i = _FileCountLines($file) $string = FileReadLine($file, $i) If StringInStr ($string, "Close") Then ExitLoop Sleep(5000) WEnd [size="1"][font="Arial"].[u].[/u][/font][/size]
Eviltim Posted September 7, 2005 Author Posted September 7, 2005 oh I did several stupid things:posted untested codelater thought of a problem with that codewent to correct the codenoticed the Eviltim was reading my bad codedeleted my post - but probably too late and wasted Eviltim's timehastely added the $line_temp = $line stuffposted what you see above(my original code only used $line which ends in EOF?)@Eviltim,as my penance, try this:#include <file.au3> $file = "C:\Temp\Command.txt" While 1 $i = _FileCountLines($file) $string = FileReadLine($file, $i) If StringInStr ($string, "Close") Then ExitLoop Sleep(5000) WEnd<{POST_SNAPBACK}>Thanks, one last question.Is it possible to add more StringInStr Lines to it?i tried this.While 1 $i = _FileCountLines($file) $string = FileReadLine($file, $i) If StringInStr ($string, "FTP_Connect", 1) Then $command = "FTP_Start" ExitLoop If StringInStr ($string, "FTP_Stop", 1) Then $command = "FTP_Stop" ExitLoop If StringInStr ($string, "FTP_Help", 1) Then $command = "FTP_Help" ExitLoop If StringInStr ($string, "FTP_Pause", 1) Then $command = "FTP_Pause" ExitLoop If StringInStr ($string, "FTP_Report On", 1) Then $command = "FTP_Report On" ExitLoop If StringInStr ($string, "FTP_Report Off", 1) Then $command = "FTP_Report Off" ExitLoop Sleep(5000) WEndi get a "wend" statement with no matching "while" statement errori think its just bad formatting on my part.
Valuater Posted September 7, 2005 Posted September 7, 2005 like this #include <file.au3> Dim $file While 1 $i = _FileCountLines($file) $string = FileReadLine($file, $i) If StringInStr ($string, "FTP_Connect", 1) Then $command = "FTP_Start" ExitLoop EndIf If StringInStr ($string, "FTP_Stop", 1) Then $command = "FTP_Stop" ExitLoop EndIf If StringInStr ($string, "FTP_Help", 1) Then $command = "FTP_Help" ExitLoop EndIf If StringInStr ($string, "FTP_Pause", 1) Then $command = "FTP_Pause" ExitLoop EndIf If StringInStr ($string, "FTP_Report On", 1) Then $command = "FTP_Report On" ExitLoop EndIf If StringInStr ($string, "FTP_Report Off", 1) Then $command = "FTP_Report Off" ExitLoop EndIf Sleep(5000) WEnd hope that helps 8)
Eviltim Posted September 7, 2005 Author Posted September 7, 2005 like this#include <file.au3> Dim $file While 1 $i = _FileCountLines($file) $string = FileReadLine($file, $i) If StringInStr ($string, "FTP_Connect", 1) Then $command = "FTP_Start" ExitLoop EndIf If StringInStr ($string, "FTP_Stop", 1) Then $command = "FTP_Stop" ExitLoop EndIf If StringInStr ($string, "FTP_Help", 1) Then $command = "FTP_Help" ExitLoop EndIf If StringInStr ($string, "FTP_Pause", 1) Then $command = "FTP_Pause" ExitLoop EndIf If StringInStr ($string, "FTP_Report On", 1) Then $command = "FTP_Report On" ExitLoop EndIf If StringInStr ($string, "FTP_Report Off", 1) Then $command = "FTP_Report Off" ExitLoop EndIf Sleep(5000) WEndhope that helps8)<{POST_SNAPBACK}>Thanks! works great!Also noticed another typo error i made in this script. If StringInStr ($string, "FTP_Connect", 1) Then$command = "FTP_Start" -- (Should be FTP_Connect)
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