Search code examples
filecopynsis

NSIS simple copy one file from another folder in program files directory to installation dir not working


I tried to create an installer to install a application. The basic stuff works fine, but I have problems, when it comes up to simply copy an existing files, which is located in some subfolder of Program Files folder. The scenario behind this, is that the application has different versions and a license file. When the app gets installed, the installer looks for an existing file, and if exists, should just copy that license file to the $INSTDIR/license folder.

Example:

 C:\Program Files (x86)\MyApp\Ver1.0\license\   // here's the location of old license file
 C:\Program Files (x86)\MyApp\Ver2.0\license\   // here to put the old license file

Following section is condensed to the relevant stuff:

Section "License of other Version"
IfFileExists '$PROGRAMFILES\MyApp\Ver1.0\license\some_license.slc' beginLicense endLicense
Goto endLicense
beginLicense:
  MessageBox MB_OK "We have found an old license file. Do you wanna to use it for current installation ?"
  CreateDirectory "$INSTDIR\license"
  CopyFiles "$PROGRAMFILES\MyApp\Ver1.0\license\some_license.slc" $INSTDIR/license/some_license.slc"
endLicense:
    MessageBox MB_OK "There were no license found."
SectionEnd

The compiling runs fine, but the installation process denotes an error when trying to copy the file. But it gives no further explanation, why it failed. I tried also using the File directive, but that produced other errors, because of using the constants in file directive (file not found, and that sort of errors) and even the script cannot compile. I tried also using a macro, mentioned here in another question of stackoverflow (sry, didnt have the link anymore), but it didnt worked for me, too. What am I doing wrong, is it not allowed to use constants in CopyFile directive ? Any help is appreciated.


Solution

  • You need to change:

    CopyFiles "$PROGRAMFILES\MyApp\Ver1.0\license\some_license.slc" $INSTDIR/license/some_license.slc"

    To:

    CopyFiles "$PROGRAMFILES\MyApp\Ver1.0\license\some_license.slc" $INSTDIR\license\some_license.slc"