Archive: Append to End of File


Append to End of File
Hi,

I am using FileOpen and FileWrite to write some stuff into a file.
I am using append mode to do this.

However, when I do FileWrite, it seems to be writing to the begining of my file and overwriting my information in the file.

I wish to write to the end of the file not from the beginning.

Can anyone please help?
Thanks.!:confused:


Write the other contents back first.


Here is one way to add text at the end of a file:


FileOpen $R1 myfile.txt a
FileSeek $R1 0 END
FileWrite $R1 "this line should appear at the end$\n"
FileClose $R1

Originally posted by pengyou
Here is one way to add text at the end of a file:


FileOpen $R1 myfile.txt a
FileSeek $R1 0 END
FileWrite $R1 "this line should appear at the end$\n"
FileClose $R1
The codes should work but here is a note:
If the file doesn't have an empty line at the end, the text
will be appended to the last line.

e.g:
This is the last linethis line should appear at the end

I think that that can be solved by writing ($\r)$\n in front of 'this line should appear at the end', making "$\nthis line should appear at the end$\n".


The best way is to set the file pointer 1 char away from END and compare that char to $\n.