Hello,
I try the following code
Var MyVar
StrCpy MyVar "C:\Path\myfile.txt"
SetOutPath "$INSTDIR"
File "$MyVar"
When I try to compile my installer I get the error message:
File "$MyVar" -> no files found.
Why is this?
If I try
File "C:\Path\myfile.txt"
it works.
Thanks,
Tieum
Variable does not expand correctly in File
6 posts
Variables are used at runtime. File is a compile-time command, so you can't use variables to define the file name.
You muse either use a 'real' name (File "C:\Path\myfile.txt") or you can use a symbol, like:
!define myFile "C:\path\mayfile.txt"
File ${myFile}
But, you can use variables to specify the output, such as:
File "/oname=$myFile" "C:\myfile.txt"
You muse either use a 'real' name (File "C:\Path\myfile.txt") or you can use a symbol, like:
!define myFile "C:\path\mayfile.txt"
File ${myFile}
But, you can use variables to specify the output, such as:
File "/oname=$myFile" "C:\myfile.txt"
The problem is !define is not "variable." I have documentation in several languages and need to be able to change the path where the documentation is taken from depending on the language on the fly. How can I achieve that?
Update just did it with !define and !undef. Thanks for the help.
Update just did it with !define and !undef. Thanks for the help.
I was just going to mention that if you wanted to control what gets installed, then here's a way that should work:
But, if you instead wanted to build an separate installation for each language, then you could probably use !ifdef blocks for each language. Example:!include LogicLib.nsh
#...
Section
${Switch} $LANGUAGE
${Case} ${LANG_ENGLISH}
File "C:\English.txt"
${Break}
${Case} ${LANG_FRENCH}
File "C:\French.txt"
${Break}
${EndSwitch}
SectionEnd
edit You might also have a look at languages.nsi included in your nsis examples folder for more ideas.!ifdef UseEnglish
; code for adding English files
!endif
it would be helpful if the FILE instruction error explained that variables cannot be used... I've been banging my head for a couple of hours on this weird fault 🙂
Variables only work on the end-users machine, not your machine. "$Whatever" is a valid filename, there is no way for the compiler to guess if you wanted a variable or if that is just the name.