HARNOvHARNO Posted January 19, 2005 Share Posted January 19, 2005 (edited) expandcollapse popup$file = FileOpen("test.html", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $text = FileRead($file, 100000) If @error = -1 Then ExitLoop Wend FileClose($file) $text = StringReplace("file:///E:/root/Apache/htdocs", "", "") $numreplacements = @error MsgBox(0, "New string is", $text) MsgBox(0, "The number of replacements done was", $numreplacements) $file = FileOpen("test.html", 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($file, $text) FileClose($file) MsgBox(0, "search", "done") i need to search a html file for text string "file:///E:/root/Apache/htdocs" and then delete it from the file as somone made a big mistake as you see. there is about 7000 wrong entries.... but i cant get my script to work, i foth this was easy. meybe somone can help me here.... Edited January 19, 2005 by HARNOvHARNO Link to comment Share on other sites More sharing options...
Lazycat Posted January 19, 2005 Share Posted January 19, 2005 (edited) Three mistakes are here: 1. Strange loop at begin, not sure why it not works, but this loop not need anyway 2. StringReplace not take your text string 3. Second time file opens in append mode, not overwrite Also, if you use latest beta num replacements now in the @extended macro. Here is fixed code: $file = FileOpen("test.html", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $text = FileRead($file, FileGetSize("test.html")) FileClose($file) $text = StringReplace($text, "file:///E:/root/Apache/htdocs", "") $numreplacements = @extended; @error MsgBox(0, "New string is", $text) MsgBox(0, "The number of replacements done was", $numreplacements) $file = FileOpen("test.html", 2) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($file, $text) FileClose($file) MsgBox(0, "search", "done") Edited January 19, 2005 by Lazycat Koda homepage ([s]Outdated Koda homepage[/s]) (Bug Tracker)My Autoit script page ([s]Outdated mirror[/s]) 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