Archive: Question about append to a file


Question about append to a file
Hello all,
I am completely new in scripting an installer, and I would to open a file to write 1 line at the end of it.

I have created a function:
Function writeLogFile ;
ClearErrors
FileOpen $0 $INSTDIR\file.dat a
IfErrors done
FileWrite $0 "new text"
FileClose $0
done:
FunctionEnd

But this write always the line on the first line of the file.
Can someone help me on this ?
Thanks !


Try FileSeek after opening the file: http://nsis.sourceforge.net/Reading_...iting_in_files


Re: Question about append to a file

Originally posted by Ben_101
Hello all,
I am completely new in scripting an installer, and I would to open a file to write 1 line at the end of it.

I have created a function:
Function writeLogFile ;
ClearErrors
FileOpen $0 $INSTDIR\file.dat a
IfErrors done
FileWrite $0 "new text"
FileClose $0
done:
FunctionEnd

But this write always the line on the first line of the file.
Can someone help me on this ?
Thanks !
Do it like this ;)

Function writeLogFile
ClearErrors
FileOpen $0 $INSTDIR\file.dat a
IfErrors done
FileSeek $0 0 END ; <-- Set pointer to the end of the file
FileWrite $0 "new text"
FileWrite $0 "$\r$\n" ; <-- Add carriage return
FileClose $0
done:
FunctionEnd


pospec was faster :D

This is working fine now.
Thank you for your help !