Archive: NSIS Check if directory exists


NSIS Check if directory exists
Greetings,

the last couple of weeks, I have been fooling arround with NSIS and taken the initiative to convert all related work to it as it would be easier to have the option of starting up the single installer that would take care of all the other installations required to be done :) (various agent software and OS tweaking ..)

now there are several subjects im facing some dificulties with, I hope some of you guys here could help me out.

due to the different operating systems and versions that are administered, I need to be able to verify whether a directory in a given path exists so i can continue processing other tasks based on that, how and what is the best way for this to be accomplished, for example, i need to find out whether c:\admtools exists or c:\foobar exists, if it does
then a variable would be flagged (myfoldervar=1)

ive tried to lookup in the forum, but i didnt find any clear answer to this,

hoping to hear from the pros soon,

regards
BL


Re: NSIS Check if directory exists

Originally posted by BashLogic
ive tried to lookup in the forum, but i didnt find any clear answer to this,
Did you try looking up the NSIS Users Manual?
Use the IfFileExists instruction.

yes i noticed that "if file exist" feature, i just wanst sure whether it is the appropriate one giving it a thought whehter "if directory exist" method exists as well :)


IfFileExists "$INSTDIR\directory\*.*" ...

-Stu


Originally posted by BashLogic
yes i noticed that "if file exist" feature, i just wanst sure whether it is the appropriate one giving it a thought whehter "if directory exist" method exists as well :)
From the NSIS Users Manual:

Checks for existence of file(s) file_to_check_for (which can be a wildcard, or a directory)
I think it speaks for itself.

Is there a way to know is it a file or directory?


Did you miss my code?

Same idea but using LogicLib:

${If} ${FileExists} `$INSTDIR\file\*.*`
; file is a directory
${ElseIf} ${FileExists} `$INSTDIR\file`
; file is a file
${Else}
; file is neither a file or a directory (i.e. it doesn't exist)
${EndIf}


Edit: Note the order of checks is important.

Stu

Thanks for the answer!

But I have found the winapi function:
http://nsis.sourceforge.net/GetFileAttributes

Good luck!


Why use that when you can just use the simple logic I gave?

Stu


First I thought, that empty dir will be detected as file.
But then I trieed everything is OK.

Thank you so much!


Yes people are misled by the use of *.* but it does cover empty directories because . is the current directory and .. is the parent directory (you will pick up . and .. as files when using FindFirst, FindNext etc).

Stu


But isn't possible to use a wildcard search on the folder level, is it, thus checking for the existence of multiple folders perhaps with similar names?:

${If} ${FileExists} `$INSTDIR\file*\*.*`


The NSIS User Manual describes several useful functions, including "Locate" which supports wildcards:
http://nsis.sourceforge.net/Docs/AppendixE.html#E.1.2

Section E.1.2 of the manual also mentions the "Locate" plugin which supports wildcards:
http://nsis.sourceforge.net/Locate_plugin


Thank you. I will take a look at it. Some of these things are much simpler when I am doing them in a C++ context. I find myself asking basic questions when it comes to the installer.