28

I can't seem to find any information about how to copy a directory using NSIS ?, i know there is a file command but is there any command to copy a directory .

4 Answers 4

41

The syntax is same for both directory and file, except that you need to specify a directory by providing a \ at the end. File command copies the directory if the specified argument is a directory. For eg, you can do:

SetOutPath "outputPath"
File "myDirectory\" #note back slash at the end

But that copies only the top level directory. To recursively do it, you have /r switch

SetOutPath "outputPath"
File /nonfatal /a /r "myDirectory\" #note back slash at the end

which copies the contents of myDirectory (but not myDirectory folder itself). /nonfatal ignores without an error if there is no particular directory. /a copies file attributes as well. /x switch is used to exclude files.

Otherwise,

SetOutPath "outputPath\myDirectory"
File /nonfatal /a /r "myDirectory\" #note back slash at the end

copies all the contents of myDirectory including myDirectory folder to outputPath.

3
  • 1
    Thanks! The last example doesn't seem to work though... To create the folder, I have to use SetOutPath $INSTDIR\myDirectory and then File /a /r "myDirectory\"
    – werner
    Jan 30, 2015 at 16:30
  • @nawfal, THANK YOU so much for stressing the '\' at the end. It was driving me CRAZY!! I didn't see anything referencing that in the NSIS documentation.
    – Damian
    May 30, 2016 at 2:43
  • Important to say it will have a side effect as does pack the directory inside the installer executable on compilation stage.
    – Andry
    Sep 14, 2017 at 13:59
5

I found how to do it , sorry for the trouble .

Extract the files to a directory which can't exist beforehand

CreateDirectory $Installdir\extracting

SetOutPath $Installdir\extracting

File Directory\*
1
  • 5
    SetOutPath already creates the passed directory and subdirectories, so calling CreateDirectory first is not necessary.
    – Claudi
    Oct 23, 2013 at 6:51
3

The File instruction extracts files from your installer and CopyFiles copies files and/or directories that already exist on the end-users system (You can use $EXEDIR if you need to copy files off a dvd where your installer is also located...)

0

The star to match the whole content after the back slash is mandatory. The syntax is the following.

See the manual section 4.9.1.6

SetOutPath "outputPath\myDirectory"
File /nonfatal /a /r "myDirectory\*" 
1
  • Why do you mention the star is mandatory after the backslash, but it's not in the code sample you provide?
    – Jeff B
    Oct 4, 2019 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.