Archive: how to write at the end of existing file?


how to write at the end of existing file?
I opened a file with "a" mode to write a file.
It seems it appends the string from the beginning of the file.
I found a solution from this forum which is:

FileOpen $0 myfile a
FileSeek $0 END
FileWrite $0 "$\r$\nstring here$\r$\n"
FileClose $0

But my file is still refreshed, not appended.
Can someone help me?


You need to specify an offset in addition to 'END'. You can use

FileSeek $0 0 END

to move to the very end of the file.

But this might not always give the result you expect - it depends upon the structure of the file (e.g. does it contain an EOF marker, do the existing lines in the file use $\r$\n or just $\n to mark the end of the line).


You should have a look at the NSIS Archive Text File Manipulation section.

There is a script on there which will write to the end of a file everytime.

-Stu