Archive: How do I copy directories?


How do I copy directories?
Am I just being daft, or is there no easy way of copying directories and files, e.g. to backup a directory structure with all files?


File /r

See NSIS documentation


lol ah yes!


Maybe I'm still being stupid, but doesn't the File command define files/directories to be included in an installation? I don't want to include the files, I simply want to copy the directories that already exist on the computer to another directory (for backup purposes).

Something like this:

; Backup existing files
IfFileExists "C:\testout\*.*" +1 SkipCopy
SetOutPath "$temp\testout\"
File /r "C\testout\"
SkipCopy:

;Install the new files
SetOutPath "C:\testout\"
File "C:\test\thedoc.txt"
File "C:\test\thedoc2.txt"

; Resotre any backed up files
IfFileExists "C:\testout\*.*" +1 SkipRestore
SetOutPath "C\testout\"
File /r "$temp\testout\"
SkipRestore:

Now, this might look pointless, but I'm covering the scenario where our users can customize files in the testout directory, and when we release updates I don't want them to lose their customized files, therefore I backup, then restore their files, but they will still recieve any new files we add.

This enables us to use the same installer for both new installs and updates. Make sense?


This enables us to use the same installer for both new installs and updates. Make sense?
Makes perfect sense, however you can't use on target, it's a compile time command. Anyway, regarding to the File command, try to use the File /r by this way "C:\testout" and by this way "C:\testout\*" to see the difference, also you may use it in combination with /x switch to exclude specific files/subdirs. e.g.

File /r /x "this_fie.ext" "C:\testout\*"

All these actions performed on system where compiling script, you can't use these to move/copy files on target system, instead you may use CopyFiles and Rename.

Yes I'm wanting to do the transfer on the target system, so the File command isn't any use. How do you use CopyFiles to copy a directory? I've tried all sorts of combinations:

CopyFiles "C\testout" "$temp\testout"
CopyFiles "C\testout\" "$temp\testout"
CopyFiles "C\testout\*.*" "$temp\testout"
CopyFiles "C\testout" "$temp\testout\"
CopyFiles "C\testout\" "$temp\testout\"
CopyFiles "C\testout\*.*" "$temp\testout\"

but nothing seems to work.


This works fine for me,

OutFile 'test.exe'

Section "boo"
CreateDirectory "C:\TEMP\test"
CopyFiles "${NSISDIR}\Plugins\*.*" "C:\TEMP\test"
SectionEnd

Ahhh it'll be because I haven't created the $temp\testout\ directory!!! <slap on head>