Old 3rd April 2009, 15:53   #1
tieum
Junior Member
 
Join Date: Mar 2004
Posts: 29
Variable does not expand correctly in File

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
tieum is offline   Reply With Quote
Old 3rd April 2009, 16:20   #2
Comperio
Major Dude
 
Comperio's Avatar
 
Join Date: Jan 2005
Location: Oregon Coast
Posts: 737
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"
Comperio is offline   Reply With Quote
Old 3rd April 2009, 18:03   #3
tieum
Junior Member
 
Join Date: Mar 2004
Posts: 29
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.

Last edited by tieum; 3rd April 2009 at 18:23.
tieum is offline   Reply With Quote
Old 3rd April 2009, 18:36   #4
Comperio
Major Dude
 
Comperio's Avatar
 
Join Date: Jan 2005
Location: Oregon Coast
Posts: 737
I was just going to mention that if you wanted to control what gets installed, then here's a way that should work:
code:
!include LogicLib.nsh
#...
Section
${Switch} $LANGUAGE
${Case} ${LANG_ENGLISH}
File "C:\English.txt"
${Break}
${Case} ${LANG_FRENCH}
File "C:\French.txt"
${Break}
${EndSwitch}
SectionEnd


But, if you instead wanted to build an separate installation for each language, then you could probably use !ifdef blocks for each language. Example:
code:
!ifdef UseEnglish
; code for adding English files
!endif

edit You might also have a look at languages.nsi included in your nsis examples folder for more ideas.
Comperio is offline   Reply With Quote
Old 16th November 2019, 11:48   #5
umeca74
Junior Member
 
Join Date: Jan 2009
Posts: 22
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
umeca74 is offline   Reply With Quote
Old 16th November 2019, 22:57   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,190
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.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump