Search code examples
nsis

NSIS - CopyFiles Directive not working with variables as parameters?


I want to copy files/folders from one folder of enduser-system to another folder of enduser-system. However the CopyFiles directive seems to be not working, when passing variables like $0, $1 as source parameter..

...
SetRegView 64
ReadRegStr $0 HKLM "${PRODUCT_HOME_ROOT}\$1" "License"
MessageBox MB_OK "$0"     
CreateDirectory '"$INSTDIR\application\license"'
CopyFiles "$0" "$INSTDIR\application\license"

The string stored in $0 is checked, and is identical to the absolute path of the file. If i pass the source parameter as "C:\path_to_folder", the CopyFiles directive is working, as expected. What am i doing wrong ?


Solution

  • A variable should work but the actual string stored in that variable should not be double quoted and it should only use backslashes (\), not forward slashes (/).

    Section
    InitPluginsDir
    CreateDirectory "$PluginsDir\Src"
    File "/oname=$PluginsDir\Src\test.txt" "${__FILE__}"
    CreateDirectory "$PluginsDir\Dst"
    StrCpy $0 "$PluginsDir\Src\test.txt"
    CopyFiles "$0" "$PluginsDir\Dst"
    ExecShell explore "$PluginsDir\Dst"
    MessageBox MB_OK "Done?"
    Quit
    SectionEnd