Greenyoda Posted November 11, 2006 Share Posted November 11, 2006 Is their a command to Read a line from a text file and search the line for a word? Then maybe delete the line? Link to comment Share on other sites More sharing options...
stampy Posted November 11, 2006 Share Posted November 11, 2006 look some of these up in the help file. It should get you started. FileRead FileReadLine _FileReadToArray StringInStr Link to comment Share on other sites More sharing options...
/dev/null Posted November 11, 2006 Share Posted November 11, 2006 Is their a command to Read a line from a text file and search the line for a word? Then maybe delete the line?Take a look at the code of _ReplaceStringInFile() (in file.au3 / include dir). That will get you started.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Uten Posted November 11, 2006 Share Posted November 11, 2006 (edited) Or maybe use StringRegExp if you want to parse the entier file. Can be a chalange thought EDIT:Try to chofe (??) up some code and I'm sure you will get help correcting it if you need some help with that. Edited November 11, 2006 by Uten Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Greenyoda Posted November 17, 2006 Author Share Posted November 17, 2006 Ok I worked on it some, Got a whole lot of code done. Then I realized that replace string would be better. So now I have: #include <file.au3>;Variables$search = "found"$replace = ""$file = FileOpenDialog ( "findme", "c:/", "" ); Check if file opened for reading OKIf $file = -1 Then MsgBox(0, "Error", "Unable to open file.") ExitEndIf;read the file_ReplaceStringInFile($file, $search, $replace, 0, 1)Msgbox( 0, "Deleted", "done boss" )Is their anyway to Have it Delete the line? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted November 17, 2006 Moderators Share Posted November 17, 2006 Look at _FileWriteToLine() since you're already using the File.au3 file, puting "" in the $sText parameter, and using 1 as the $fOverWrite parameter will delete the line. 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...
Rad Posted November 17, 2006 Share Posted November 17, 2006 EDIT:Try to chofe (??) up some code and I'm sure you will get help correcting it if you need some help with that.chofe = cough?hehe Link to comment Share on other sites More sharing options...
Greenyoda Posted November 17, 2006 Author Share Posted November 17, 2006 Hmm I tried but their is still something Wrong. can someone look over the code and point out errors?#include <file.au3>;Variables$search = "found"$file = FileOpenDialog ( "findme", "c:/", "" ); Check if file opened for reading OKIf $file = -1 ThenMsgBox(0, "Error", "Unable to open file.")ExitEndIf;read the fileWhile 1 $x = 1 FileReadLine( $file, $x ) $isittheir = StringInStr( "found", "found" )if $isittheir > 0 Then _FileWriteToLine($file, $x, 1) $x = $x + 1ElseIf @error = -1 Then FileClose ( $file ) MsgBox( 0, "Done", "We are done" )EndIfWEnd Link to comment Share on other sites More sharing options...
stampy Posted November 18, 2006 Share Posted November 18, 2006 The FileReadLine wasn't actually going into a variable and the StringInst was searching for "found" inside of "found". Try this. #include <file.au3> ;Variables $search = "found" $file = FileOpenDialog ( "findme", "c:/", "" ) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ;read the file While 1 $x = 1 $line = FileReadLine( $file, $x ) $isittheir = StringInStr( $line, "found" ) if $isittheir > 0 Then _FileWriteToLine($file, $x, 1) $x = $x + 1 ElseIf @error = -1 Then FileClose ( $file ) MsgBox( 0, "Done", "We are done" ) EndIf WEnd Link to comment Share on other sites More sharing options...
Greenyoda Posted November 18, 2006 Author Share Posted November 18, 2006 Nope, Still not deleting it:( Link to comment Share on other sites More sharing options...
stampy Posted November 18, 2006 Share Posted November 18, 2006 The fileWriteToLine need some text sent to it. _FileWriteToLine($sFile, $iLine, $sText[, $fOverWrite]) If you wish to delete the line all together send a blank sting. _FileWriteToLine($file, $x,"", 1) Give that a shot. Link to comment Share on other sites More sharing options...
Greenyoda Posted November 18, 2006 Author Share Posted November 18, 2006 #include <file.au3> ;Variables $search = "found" $file = FileOpenDialog ( "findme", "c:/", "" ) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $x = 1 $numbers = 0 ;read the file While 1 $line = FileReadLine( $file, $x ) $isittheir = StringInStr( $line, $search ) if $isittheir > 0 Then _FileWriteToLine($file, $x, "", 1) TrayTip("The number of lines deleted",$numbers , 5) $x = $x + 1 $numbers = $numbers + 1 ElseIf $line = -1 Then FileClose ( $file ) MsgBox( 0, "Done", "We are done" ) EndIf WEnd I changed it out but it didnt seem to work:( Link to comment Share on other sites More sharing options...
xcal Posted November 18, 2006 Share Posted November 18, 2006 (edited) Try this out: #include <File.au3> Dim $array $file = FileOpenDialog('Choose Your File', 'c:\', 'All Files (*.*)') $find = InputBox('What To Find', 'Type in below what to search for.' & @CRLF & _ 'Lines that match will be removed.', 'Text To Match', '', 200, 140) $found = 0 $lines = '' If $file <> '' And $find <> '' Then _FileReadToArray($file, $array) For $i = 1 To UBound($array) - 1 If StringInStr($array[$i], $find) Then $array[$i] = '' $found += 1 $lines &= $i & ', ' EndIf Next _FileWriteFromArray($file, $array, 1) MsgBox(64, 'Done', 'Total lines found = ' & $found & @CRLF & _ 'Removed line number(s) = ' & StringTrimRight($lines, 2)) Else MsgBox(48, 'Error', 'A file was not picked or what to find was cancelled/empty!') EndIf -edit 1 small change -edit 2 wrong msgbox icon -edit 3 nothing worth noting... just picking at it Edited November 18, 2006 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
Greenyoda Posted November 18, 2006 Author Share Posted November 18, 2006 Thanks a bunch Xcal!!! Works Perfectly:) Any way to make it delete the spaces? Link to comment Share on other sites More sharing options...
/dev/null Posted November 18, 2006 Share Posted November 18, 2006 Any way to make it delete the spaces? Spaces in general? --> StringReplace() Empty lines? --> look at the code of _FileWriteFromArray (file.au3). Copy that code and modify it. Don't write a line if it's empty(StringLen($a_Array[$x]) = 0). Cheers Kurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * 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