Archive: Getting IfFileExists to work for a directory


Getting IfFileExists to work for a directory
I have been trying, unsuccessfully, to get NSIS to include a directory in my installer if the directory exists and to skip the attempt to include the directory if it does not exist. I have tried every combination of the IfFileExists instruction and even tried using the LogicLib.nsh include as follows:

${If} ${FileExists} "${ZB_DOCS_PATH}\*.*"
DetailPrint 'Source file "${ZB_DOCS_PATH}\*.*" exists'
; Add the documentation directory and files to the installer
SetOutPath $INSTDIR
File /r /x CVS ${ZB_DOCS_PATH}
${Else}
DetailPrint 'Source file "${ZB_DOCS_PATH}\*.*" does not exist'
${EndIf}

I am runing this from inside of a Section.

Each time I run this, with or without the "\*.*", the app attempts to include the ${ZB_DOCS_PATH} directory in the installer whether it exists or not. If it does not exist, then the build fails. Here is the output I am seeing when the directory does exist:

!insertmacro: _If
!insertmacro: end of _If
DetailPrint: "Source file "..\..\documentation\*.*" exists"
SetOutPath: "$INSTDIR"
File: Descending to: "..\..\documentation\"
File: "fred.txt" [compress] 17/19 bytes
File: Returning to: "..\.."
!insertmacro: _Else
!insertmacro: end of _Else
DetailPrint: "Source file "..\..\documentation\*.*" does not exist"
!insertmacro: _EndIf
!insertmacro: end of _EndIf

This looks like it is going through both the IF and the ELSE which doesn't make sense.

The documentation folder is not included in the installer in this case. When I do the same using the IfFileExists instruction, the folder is included if it is present, but fails if it is not present. I have tried using Goto Labels and offsets to no avail.

When running the same compile without the documentation folder being present as defined by ${ZB_DOCS_PATH} the build failes with the following:

!insertmacro: _If
!insertmacro: end of _If
DetailPrint: "Source file "..\..\documentation\*.*" exists"
SetOutPath: "$INSTDIR"
File: Returning to: "..\.."
File: "..\..\documentation" -> no files found.
Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
/oname=outfile one_file_only)
Error in script "C:/builds/Clients/Ankus_R1-0/trunk/hcrest.zuibrowser.win32/../hcrest.zuibrowser.win
32/installer/ZuiBrowserInstaller.nsi" on line 166 -- aborting creation process
NMAKE : fatal error U1077: '"C:\Program Files\NSIS\makensis.exe"' : return code '0x1'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio .NET 2003\VC7\BIN\nmake.exe"'
: return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio .NET 2003\VC7\BIN\nmake.exe"'
: return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio .NET 2003\VC7\BIN\nmake.exe"'
: return code '0x2'
Stop.

In this case the source file "..\..\documentation\*.*" definitely does not exist, yet NSIS is still going into the IF section rather than the ELSE section.

Any help would be appreciated. I am using v2.24, but this happens for earlier versions as well.

Thanks,

Jay Renbaum


That's a common misunderstanding, you're trying to execute run time commands at compile time.


OK,

That makes sense. That being said, is there a way to do what I want? Have NSIS include the folder in the installer if it is present, but not event try to include it if it is not present?


Define that folder by executing makensis from command line with /D switch and use !ifdel in your script to include/exclude the folder.

Also take a look at this thread, might be helpful,

http://forums.winamp.com/showthread....hreadid=265319