Valuater Posted September 1, 2005 Share Posted September 1, 2005 I know this was asked a while back.. but i can't find the thread FileReadLine will read a specific line number... how can i write/replace that file line of text FileWriteLine, as far as i know, does not accept a line # thx 8) Link to comment Share on other sites More sharing options...
AutoChris Posted September 1, 2005 Share Posted September 1, 2005 (edited) You silly: From the Help File: FileWriteLine ( filehandle or "filename", "line") Edit: Formatting issues Edited September 1, 2005 by SerialKiller Link to comment Share on other sites More sharing options...
Valuater Posted September 1, 2005 Author Share Posted September 1, 2005 (edited) You silly:From the Help File:FileWriteLine ( filehandle or "filename", "line")Edit: Formatting issues<{POST_SNAPBACK}>at first i thought you had a newer version of beta..... then maybe that was a trick statement.... but nohere is what i foundFileWriteLine ( filehandle or "filename", "line" )Parametersfilehandle The handle of a file, as returned by a previous call to FileOpen. Alternatively, you may use a string filename as the first parameter. line The line of text to write to the text file. If the line does NOT end in @CR or @LF then a DOS linefeed (@CRLF) will be automatically added. so this is text not an actual line number... sillylol8) Edited September 1, 2005 by Valuater Link to comment Share on other sites More sharing options...
AutoChris Posted September 1, 2005 Share Posted September 1, 2005 (edited) Dag-blammit! You're right. I am silly.I just remembered using FileReadLine() in a previous script. What I had done was use FileReadLine() and then use StringReplace() to overwrite that line of text.Sorry for being dumb. Edit: Dumb mistake Edited September 1, 2005 by SerialKiller Link to comment Share on other sites More sharing options...
Valuater Posted September 1, 2005 Author Share Posted September 1, 2005 Dag-blammit! You're right. I am silly.I just remembered using FileReadLine() in a previous script. What I had done was use FileReadLine() and then use StringReplace() to overwrite that line of text.Sorry for being dumb. Edit: Dumb mistake<{POST_SNAPBACK}>are you saying you were able to replace the text in that line... in that text file??or have any ideas how?8) Link to comment Share on other sites More sharing options...
AutoChris Posted September 1, 2005 Share Posted September 1, 2005 are you saying you were able to replace the text in that line... in that text file??or have any ideas how?8)<{POST_SNAPBACK}>Yes. The script I wrote had to insert new information into a text file because the data was constantly being updated. So I knew what text I was looking for so I did a StringReplace() and changed that line of text. If you only know certain keywords, then StringInStr() will work along with StringTrim...(). Link to comment Share on other sites More sharing options...
Valuater Posted September 2, 2005 Author Share Posted September 2, 2005 ok, i am trying to understand the useage here's the process open the file read the line of text use string replace and???... how to write/replace that line of text in the file close the file 8) Link to comment Share on other sites More sharing options...
AutoChris Posted September 2, 2005 Share Posted September 2, 2005 Open the file.Read the line of text (sticking it into a variable)Do a string replace (variable) and replace it with whatever text you want. Close the file.I actually rarely use FileReadLine() since I rarely know what line the text might be on. I typically use $var = FileRead($thetextfileIamreading, FileGetSize($thetextfileIamreading)). And then I do a StringReplace() on $var so that it is sure to find it since I stuck the whole text file into the variable.I hope this helps. If not, good luck to you because I am about to go home and take a nap. After being both dumb and silly in one day, I need it. Link to comment Share on other sites More sharing options...
Valuater Posted September 2, 2005 Author Share Posted September 2, 2005 ok i will try again ; line #7 of text.txt = "my computer,fire fox, xpclean menu, developer" $search = FileOpen("C:\text.txt", 0) If $search = -1 Then MsgBox(0, "Error", "File not found") Exit EndIf $read = FileReadLine($search, 7) $names = StringSplit($read, ",") if $names[1] <> "" then $names[1] = "Your computer" for $i = 1 to $names[0] MsgBox(0,"names", $names[$i]) Next ; FileWriteLine(????????) FileClose("C:\text.txt") ; i want line #7 to have this ; line #7 of text.txt = "your computer,fire fox, xpclean menu, developer" can this be done.... how????? 8) Link to comment Share on other sites More sharing options...
AutoChris Posted September 2, 2005 Share Posted September 2, 2005 Okay, here is a quick script: $file = "c:\text.txt" $read = FileRead ($file, FileGetSize ($file)) $read = StringReplace($read, "my computer", "your computer") FileOpen ($file, 2) FileWrite ($file, $read) FileClose ($file) Hopefully this gets you on your way to whatever you are writing. Link to comment Share on other sites More sharing options...
MHz Posted September 2, 2005 Share Posted September 2, 2005 @ ValuaterSerialKiller shows a good concept to use. Do note that AutoIt cannot replace a single line in a text file without re-writing the whole file back to disk. If it is a big file, then _FileReadToArray maybe a better choice?, as it reads and writes lines to a new file quicker then reading the whole file FileRead, replacing, then Filewriting it.A 3rd party tool like Gsar can be used to search and replace in a text file. But that is external and adds 60+ kb to your program.HTH 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