Archive: FileOpen and FileWrite


FileOpen and FileWrite
  I want Open a file an than i want Write a Strin i this file.But how is the Problem.


Function open
FileOpen $0 $INSTDIR\dir1\file1.cfg w
FileWrite $0 Read this
FunctionEnd

Soory for my bad english.
Soory for the so simpel Problem but i was a beginner.


What is the problem?

A few possible reasons for whatever problem it is:
1) You forgot FileClose
2) If you want to add to the file use the a mode (append) instead of w (write).
3) You must seek to the end of the file using FileSeek if you don't wish to overwrite anything.
4) You forgot to quote Read This. The line should be FileWrite $0 "Read This". If you don't quote, NSIS will treat this as two strings and the word "This" will be treated as the maximum length of the string to write.


Function open
FileOpen $0 $INSTDIR\dir1\file1.cfg a
FileSeek $0 offset END $1
FileWrite $0 "Read This"
FileClose $0
FunctionEnd


1 warning:
install function "open" not referenced - zeroing code (6-10) out


Functions don't get executed by the installer just like that. Sections are executed according to the user selection, callback functions (.on* and un.on*) get called according to special events, but regular functions must be called manaually using Call.

Offset should be a number. If you wish to seek to the end use `FileSeek $0 0 END`.

Here is an example script for the functions stuff:


Name "asd"

>OutFile "asdsad.exe"

>Function doStuff
DetailPrint "i am doing stuff..."
>FunctionEnd

Section "install files"
; install files
; write to the registry
Call doStuff; do other stuff
; install some more
; Call doStuff ; do other stuff again
SectionEnd
>

ok thx it is super.

but ihave test it.

File before

sdfsdfsf
sdfsdfsf
sdfsdfsf
sdfsdfsf
sdfsdfsf
sdfsdfsf

File after

sdfsdfsf
sdfsdfsf
sdfsdfsf
sdfsdfsf
sdfsdfsf
sdfsdfsfRead This

But the file must be

sdfsdfsf
sdfsdfsf
sdfsdfsf
sdfsdfsf
sdfsdfsf
sdfsdfsf
Read This

The srcibt is.

Section open
FileOpen $0 $INSTDIR\cstrike\autoexec.cfg a
FileSeek $0 0 END
FileWrite $0 "Read This"
FileClose $0
SectionEnd


If you want to make sure it goes down a line just add $\r$\n to the beginning of the line. FileWrite $0 "$\r$\nNew line!"