- NSIS Discussion
- Using File instruction to copy entire folders
Archive: Using File instruction to copy entire folders
Ron.Stordahl
12th October 2011 23:04 UTC
Using File instruction to copy entire folders
I am successfully copying individual files to my INSTDIR using:
SectionIn RO
SetOutPath"$INSTDIR" ;The 'program files' will go in this location
SetOverwrite ON ;Overwrite existing files.
>File "..\BPQ32\Files\AGWtoBPQ.exe"
>File "..\BPQ32\Files\BPQ32.EXE"
>File "..\BPQ32\Files\BPQadapters.exe"
>...and continuing for about a dozen more individual filenames
>
But next I want to copy a folder named Documents and all it contents including subfolders so I tried
File "..\BPQ32\Files\Documents"
But it failes with:
File: "..BPQ32\Files\Documents" > no files found. I have also tried Documents\" and Documents\*.*" to no avail. In INSTDIR I want to add the Document subfolder and all it contents. I realize it says no files found, but there is a Documents folder at the same level as the individual files successfully being copied so there must be a similar way to specify it. I must not be specifying this correctly?
LoRd_MuldeR
12th October 2011 23:38 UTC
The "File" command doesn't copy files.
Instead the File command will scan for the specified file(s) at compile-time, i.e. on the machine where the installer is compiled!
The file(s) will then be built-in into the installer executable. And, at install-time, they'll be extracted to the current $OUTDIR.
Also, when specifying a relative path, e.g. "..\BPQ32\Files\Documents", it is interpreted relative to the directory where the .NSI file is located.
So if you want to copy files, at install-time, you have to use the CopyFiles command instead...
demiller9
13th October 2011 01:16 UTC
Check the manual. You need the /r switch.
Ron.Stordahl
13th October 2011 02:00 UTC
OK, copy files was not the right term. The 'File' command does extract and place files in my instance in the INSTDIR folder and "..\BPQ32\Files\filename" does place the given file name where I want it at install time. So the relative path I am expressing is understood by 'File'. What I am trying to do is to use in in a form which places entire folders not just named files. Thus I thought ..\BPQ32\Files\Documents or some variation on that describing the folder I want to extract and place at INSTDIR would work. But it doesn't. Is there some way to use perhaps a wildcard expression to place an entire folder and all it's subfolders and contents?
I did try the /r switch and it worked inconsistently. At install times it would work often, but at other times it would error out with something like 'unable to write file.' I am not at my office now so I don't have my notes to give the exact message. But it was not consistent.
So I was looking for some other way to do the job.
LoRd_MuldeR
13th October 2011 10:57 UTC
Originally posted by Ron.Stordahl
I did try the /r switch and it worked inconsistently. At install times it would work often, but at other times it would error out with something like 'unable to write file.' I am not at my office now so I don't have my notes to give the exact message. But it was not consistent.
This kind of error message usually means one of these:
(1) The file that your installer is going to write (or at least one of the files that your installer is going to write) already exists and can not be overwritten. This can happen because the file is locked by another process or because of insufficient access rights.
(2) The file (or directory) can not be created at the desired location, because of insufficient access rights.
(3) The target device is out of free disc space.
You are using "RequestExecutionLevel admin"
and check for Admin rights with UserInfo plug-in ???
Ron.Stordahl
13th October 2011 15:57 UTC
I use the following code to check that I have admin rights
userInfo
::getAccountType ;This gets the account type and puts it in the stack
pop$0
${If} $0 == "Admin"
!ifdef debug_display
messageBox MB_ICONINFORMATION "900-.onInit: Executing with Administrator privileges"
!endif
${Else}
!ifdef debug_display
messageBox MB_ICONINFORMATION "910-.onInit: not admin: $0"
!endif
${If} ${AtLeastWinNT4}
messageBox MB_ICONINFORMATION "920-Administrator Privileges are required to install BPQ32"
abort
${Endif}
${Endif}
I also check that the BPQ32 application (the one that I am installing or updating) is not running. If it is I abort with a message. The fault has occurred when writing to either %programfiles% and to %appdata%. But if I rerun the installer typically it does not fault, or it it does it is with a different file. I suppose it is possible that Microsoft Security Essentials could be reading the exact file at the time, I can't think of any other program that would be assigned. I have changed SetOverWrite ON immediately proceeding to SetOverWrite TRY, but have not done sufficient testing to see if this matters. One has to run the installer many times before the error occurs, so it is difficult to test for this.
You mentioned the 'Userinfo' plugin. What will this tell me re Admin rights that my preceeding example won't? Also where do I get that plugin?
LoRd_MuldeR
13th October 2011 16:00 UTC
You should also add "RequestExecutionLevel admin" to add a proper Manifest for Vista+ support.
(UAC will automatically elevate NSIS installers that do not have a Manifest at all, but explicitly requesting the elevation via Manifest is safer and more correct. And, by the way, I think you can skip the ${AtLeastWinNT4} check nowadays)
Also an Antivirus program should never cause file-access to fail, it only can delay the file access while it's scanning the file.
(I use MSE too and do not experience such behavior)