treaz
28th March 2003 21:32 UTC
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:
Joost Verburg
28th March 2003 21:33 UTC
Write the other contents back first.
pengyou
28th March 2003 23:59 UTC
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
matini
29th March 2003 09:46 UTC
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
virtlink
29th March 2003 10:31 UTC
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".
kichik
29th March 2003 12:07 UTC
The best way is to set the file pointer 1 char away from END and compare that char to $\n.