quicksilver Posted July 31, 2008 Posted July 31, 2008 Hi what is the fastest way to open a Textfile and search a string with return .. i need a statement if the string in the file or not. Can Anyone help me ?
erik7426 Posted July 31, 2008 Posted July 31, 2008 Hi what is the fastest way to open a Textfile and search a string with return .. i need a statement if the string in the file or not. Can Anyone help me ? If I understood what you are looking for, this should do it. $file = FileOpen("c:\test.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $StringTest = 0 While 1 $lines = FileReadLine($file) If @error = -1 Then ExitLoop $result = StringInStr($lines,"STRING TO SEARCH FOR") If $result > 0 Then $StringTest = 1 EndIf Wend FileClose($file) If $StringTest = 0 Then MsgBox(0,"","String NOT Found") Else MsgBox(0,"","String is Present") EndIf
Gigglestick Posted July 31, 2008 Posted July 31, 2008 (edited) A simple FileRead and StringInStr will do it quickly: $file = "C:\boot.ini" $search = "Windows" If FileExists($file) Then $contents = FileRead($file) If @error Then MsgBox(0, 'File Error', $file & ' could not be read.') Else If StringInStr($contents, $search) Then MsgBox(0, 'Positive', $file & ' does contain the text "' & $search & '"') Else MsgBox(0, 'Negative', $file & ' does NOT contain the text "' & $search & '"') EndIf EndIf EndIf Edited July 31, 2008 by c0deWorm My UDFs: ExitCodes
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