8

I have a directory structure that needs to be added to the installer. I have 3 different versions of my install script, and one of them being an upgrade script, requires excluding a certain file and a subdirectory within my install directory. So I do the following:

File /r  /x ${InputDir}\data\someFile.xml /x ${InputDir}\data\derbydb\runtime\*.* ${InputDir}\*.*

The xml file and the derbydb directory are already present (since this is an upgrade) and hence I don't want to overwrite them. Yet on running the installer I clearly see that both files are overwritten, and moreover viewing the generated setup.exe with 7zip shows that they got added as well. One may as well have just called

File /r ${InputDir}\*.*

So what's going wrong here? I wish NSIS would have better documentation or list caveats with their command parameters/syntax. (/rant)

9 Answers 9

9

NSIS manual (http://nsis.sourceforge.net/Docs/Chapter4.html) section 4.9.1.5 File contains the following:

Use the /x switch to exclude files or directories.

I tried to use different variants, but only one worked:

SetOutPath $INSTDIR
File /r /x Config ..\MyProgram\*.*

where "Config" is a directory "MyProgram\Plugins\Config". NSIS searches only by name and it will be wrong to set any subfolders (e.g. "/x Plugins\Config" or "/x $INSTDIR\MyProgram\Plugins\Config\"). There is one lack: if you have the same folders in different directories, using the /r switch, both matching directories and files will be searched.

4

Finally cracked it after pulling some of my hair out...

First exclude the whole sub directory from the *.*

File /r /x "subfolder" "C:\App\bin\*.*"

then change your output directory in to your subfolder...

SetOutPath "$INSTDIR\subfolder"

then exclude the xml files...

File /r /x "*.xml" "C:\App\bin\subfolder\*.*"

and then set the output path back to how it was...

SetOutPath "$INSTDIR"

so it should look somthing like this...

SetOutPath "$INSTDIR"
File /r /x "subfolder" "C:\App\bin\*.*"
SetOutPath "$INSTDIR\subfolder"
File /r /x "*.xml" "C:\App\bin\subfolder\*.*"
SetOutPath "$INSTDIR"
1
  • Wish I could mark this as the answer, but I haven't worked again on NSIS since then so can't confirm.
    – Rex
    Commented Mar 4, 2019 at 5:59
3

I find that

File /x "${DIRECTORY}Foo.img" "${DIRECTORY}*.img"

does NOT exclude Foo.img at compilation time - it is included with the other .img files.

2

I think the problem is that you shouldn't be specifying the full path to the files to exclude just a pattern, so in other words the command should look like this:

File /r  /x data\someFile.xml /x data\derbydb\runtime\*.* ${InputDir}\*.*
1
  • I've already tried this and it doesn't work. It still includes the xml file inside the installer, and overwrites what's already there.
    – Rex
    Commented Jan 30, 2012 at 7:15
2

The /x is for excluding some files to be included in the installer at compile time.

If I understand correctly, you want to avoid the overwriting of files during the installation / upgrade at run time.

Thus you could use the SetOverwrite compiler flag before the File directive. Look at the manual section 4.8.2.8 SetOverwrite, the section 4.8.2 also shows a method to handle SetOverwrite dynamically.

6
  • But the point is that it doesn't exclude them even at compile time. If I open the generated setup file I can see that it contains the files I wanted to exclude.
    – Rex
    Commented Jan 31, 2012 at 13:37
  • @Rex: Well, the documentation does not seem to state explicitly that directory paths are supported for /x as they are for /r... It says : /x file|wildcard
    – Seki
    Commented Jan 31, 2012 at 13:52
  • But it doesn't work even for files, whether you use a wildcard or provide an exact path.
    – Rex
    Commented Feb 1, 2012 at 14:32
  • @Rex: The problem is something else, because I do use /x in my own installers, e.g. File /nonfatal /r /x .svn /x *.pl "${InstSrcFiles}\excel" (in this case .svn is a folder and *.pl are files). Are you sure that the ${InputDir} is correct ?
    – Seki
    Commented Feb 2, 2012 at 11:05
  • I suppose it is, because it's able to process ${INPUTDIR}*.* correctly. I've also tried not specifying input dir in the /x, i.e. just using data\file.xml, or data*.xml and neither work.
    – Rex
    Commented Feb 3, 2012 at 18:54
1
var pname
!define pname "Salt v1.2.9.3c"
File /r /x small-games.info.url "E:\Games\${pname}\*.*"

include E:\Games\${pname}*.*, but exclude small-games.info.url in folders

1

It seems to me there's a bug which is that if you do:

File /r "C:\folder a\subfolder b"
File /r /x "subfolder b" "C:\folder b"

then C:\folder b\subfolder a\subfolder b will still get copied as part of the first operation.

0

working example for files = File /r /x *.jpg D:\Desktop\NSIS\Examples\wp_test_build*.

working example for folders = File /r /x Config D:\Desktop\NSIS\Examples\wp_test_build*.*

0

When the folder to be excluded is a sub-folder, just use the form "File /r /x subFolderName", where the subFolderName should be the name of the subfolder itself, not containing any name of the parent folders from "$INSTDIR".

Your Answer

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

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