NSIS - File /x doesn't exclude files/directories as claimed
Asked Answered
S

9

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)

Shantae answered 27/1, 2012 at 9:23 Comment(0)
L
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.

Louvenialouver answered 30/4, 2013 at 4:59 Comment(0)
D
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"
Dinh answered 27/2, 2019 at 18:12 Comment(1)
Wish I could mark this as the answer, but I haven't worked again on NSIS since then so can't confirm.Shantae
D
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.

Depredate answered 6/8, 2012 at 22:40 Comment(0)
D
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}\*.*
Denyse answered 27/1, 2012 at 16:55 Comment(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.Shantae
M
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.

Meathead answered 30/1, 2012 at 12:27 Comment(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.Shantae
@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|wildcardMeathead
But it doesn't work even for files, whether you use a wildcard or provide an exact path.Shantae
@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 ?Meathead
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.Shantae
@Rex: I notice that I am adding a whole dir byt its name and without specifying *.*. Matybe that it is your caveat ? I will try to look at NSIS source to see if *.* is not overwritting the /x parameter. I agree with you that the NSIS documentation is perfectible :pMeathead
A
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

Ard answered 12/9, 2014 at 5:55 Comment(0)
U
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.

Ultramontane answered 5/1, 2017 at 12:55 Comment(0)
P
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*.*

Persist answered 23/11, 2022 at 16:35 Comment(0)
S
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".

Stardom answered 12/10, 2023 at 18:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.