Archive: Unable to write to a text file


Unable to write to a text file
Hi all,

I have my own function named myFunc2 which has the following two pieces of codes:

When trying to write to the installation directory i am not able to see any text file. However in the second case when I try to write to a text file to a fixed location (C:\Program Files) I am able to create a file with the correct text. Can anyone tell me how to rectify the problem since I want the text file to be created in the current installation directory rather than a fixed folder.

Push "Hello"
Push "$INSTDIR\log1.txt"
Call WriteToFile

Push "Hello"
Push "C:\Program Files\log.txt"
Call WriteToFile

Many thanks.


I suspect you're trying to write to $INSTDIR\log1.txt before its creation when actually $INSTDIR is an empty string.
You should do that either in installation section or in a function after.


Unable to write to a file
Hi,

Using $INSTDIR in the installation section works fine. But for my purpose, i am using it in a function which is below the installation section. The structure is as follows.

Installation Section
$INSTDIR works fine
SectionEnd
.
.
. (some other sections and functions)
.
.
Function myFunc2
$INSTDIR does not return the installation path.
FunctionEnd

Please advice as I have to use it in myFunc2. Is there any other way to save the $INSTDIR value from the installation section and then use it later??

Very new to NSIS :). Many thanks


Try to debug that with a message box e.g.
Function MyFunction2
MessageBox MB_OK "$INSTDIR"
FunctionEnd

You can declare a user variable e.g. Var MyVar and use it to store the $INSTDIR e.g
Section "Main Section"
StrCpy $MyVar "$INSTDIR"
......