Skip to content
⌘ NSIS Forum Archive

Question about append to a file

4 posts

Ben_101#

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 !
LoRd_MuldeR#
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 😁