Ben_101
22nd July 2008 13:12 UTC
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 !
pospec
22nd July 2008 13:15 UTC
Try FileSeek after opening the file: http://nsis.sourceforge.net/Reading_...iting_in_files
LoRd_MuldeR
22nd July 2008 13:16 UTC
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
Ben_101
23rd July 2008 13:17 UTC
This is working fine now.
Thank you for your help !