Archive: NSIS is copying directory and strange files its not asked to


NSIS is copying directory and strange files its not asked to
I have strange issue, and I'm not sure if its a bug in the compiler. Please help me with what I'm missing. I have created a simple installer to reproduce it.

My folder structure looks like this:

installer script.nsi
bin (folder) -> main file.txt
-> Installer (folder) -> ShellUtil (folder) -> ShellUtil.tlb
ShellUtil (folder) -> ShellUtil.tlb


It is this script I try to run. What I try to do in the script is:

1. Copy "main file.txt" in "bin" folder to install directory ($INSTDIR) - works fine

2. Copy "ShellUtil.tlb" in "ShellUtil" folder to install directory ($INSTDIR) - works fine

3. Copy whatever is in "ShellUtil" folder to "$INSTDIR\Installer" folder. So in step 3, this should happen after installation (assuming I install to "C:\Program Files\ABC\")

C:\Program Files\ABC -> Installer (folder) -> ShellUtil (folder) -> ShellUtil.tlb


But what I get is:

C:\Program Files\ABC -> Installer (folder) -> ShellUtil (folder) -> ShellUtil.tlb #this line is fine
-> bin (folder) -> Installer (folder) -> ShellUtil (folder) -> ShellUtil.tlb


That is additionally a "bin" folder is added to "C:\Program Files\ABC\Installer" and certain file goes into it. I do not know what has gone wrong there. I did not ask NSIS to copy folder "Installer" in "bin" folder at the time of compiling.

This is my code:


Section "Install Core Files" Section1

SectionIn RO

SetShellVarContext all #important
!insertmacro MUI_HEADER_TEXT "Installation in progress " "Please wait"

SetOutPath $INSTDIR
File "bin\main file.txt"

SetOutPath $INSTDIR
File "ShellUtil\ShellUtil.tlb"

;installer section
SetOutPath "$INSTDIR\Installer"
File /a /r "ShellUtil"

SectionEnd


For the complete test case, I have attached a trimmed setup which does exactly this :(

According to the manual it is behaving correctly. You need to use "\*.*" after the ShellUtil in the third file command.

File /a /r ShellUtil\*.*


File /r something
will match the directory named something on the root directory, the file named something in the directory named dir and the directory named something in the directory named another. To match only the directory named something on the root directory, use the following:

File /r something\*.*

@demiller9, even that wont work because I want whatever is in "ShellUtil" folder to get copied including "ShellUtil" folder.

So this works:

SetOutPath "$INSTDIR\Installer\ShellUtil"

File /a /r "ShellUtil\"


1. As you see I have to write "ShellUtil" twice. Is there someway I can instruct NSIS to copy "ShellUtil" folder including that folder to some directory?

2. An additional question: This is what I got from documentation:

If just one path segment is specified (e.g. File /r something), the current directory will be recursively searched. If more than one segment is specified (e.g. File /r something\*.*), the last path segment will be used as the matching condition and the rest for the directory to search recursively. If a directory name matches, all of its contents is added recursively. Directory structure is preserved.
In my case, the directory name matches since "ShellUtil" is a folder available in the root directory. Why is it alone not copied recursively?

I'm not sure why you object to putting "ShellUtil" in both the SetOutPath and the File commands, but I found a solution that avoids that.

First you'll have to change the input directory structure. Create any new directory (I called it CopyThis), and move the ShellUtil folder under that directory.

Next, the second File command has to change because it was using ShellUtil (this seems like a mistake, as you have a separate ShellUtil.tlb under the bin folder). Change the "File ShellUtil\ShellUtil.tlb" to either File CopyThis\ShellUtil\ShellUtil.tlb or File bin\Installer\ShellUtil\ShellUtil.tlb.

Last, change the third File command to File /a /r "CopyThis\ShellUtil"

This works because it doesn't allow the bin folder to be searched, instead the recursive search starts in CopyThis and the ShellUtil folder is a match.


Originally posted by nawfal
2. An additional question: This is what I got from documentation:

In my case, the directory name matches since "ShellUtil" is a folder available in the root directory. Why is it alone not copied recursively?
The current directory is searched recursively, not just the folder that matched. The recursive search goes into bin and matches the ShellUtil inside there, so it duplicates that directory structure. The documentation said this would happen; the piece I quoted mentioned that 'something' would be copied three times because it matched that many times in the directory structure they listed for their example.
File /r something
will match the directory named something on the root directory, the file named something in the directory named dir and the directory named something in the directory named another.

@demiller9

Thanks, that was helpful. It was little annoying to see NSIS behaving this way. "File /r something" copying too many other things from the contained directory?? What would have been obvious would be if it copied just "something" or things within it.