Jump to content

File write line # question


Valuater
 Share

Recommended Posts

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 no

here is what i found

FileWriteLine ( filehandle or "filename", "line" )

Parameters

filehandle 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... silly

lol

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

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. :whistle:

Edit: Dumb mistake

Edited by SerialKiller
Link to comment
Share on other sites

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.  :whistle:

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)

NEWHeader1.png

Link to comment
Share on other sites

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

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. :whistle: After being both dumb and silly in one day, I need it.

Link to comment
Share on other sites

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)

NEWHeader1.png

Link to comment
Share on other sites

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

@ Valuater

SerialKiller 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...