- NSIS Discussion
- NSIS Check if directory exists
Archive: NSIS Check if directory exists
BashLogic
12th June 2006 13:38 UTC
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
iceman_k
12th June 2006 14:38 UTC
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.
BashLogic
12th June 2006 16:48 UTC
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 :)
Afrow UK
12th June 2006 17:37 UTC
IfFileExists "$INSTDIR\directory\*.*" ...
-Stu
iceman_k
12th June 2006 18:14 UTC
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.
kekc
19th June 2009 14:01 UTC
Is there a way to know is it a file or directory?
Afrow UK
19th June 2009 14:37 UTC
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
kekc
19th June 2009 14:43 UTC
Thanks for the answer!
But I have found the winapi function:
http://nsis.sourceforge.net/GetFileAttributes
Good luck!
Afrow UK
19th June 2009 15:37 UTC
Why use that when you can just use the simple logic I gave?
Stu
kekc
23rd June 2009 08:01 UTC
First I thought, that empty dir will be detected as file.
But then I trieed everything is OK.
Thank you so much!
Afrow UK
23rd June 2009 15:08 UTC
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
SteveRussell
6th March 2010 21:20 UTC
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*\*.*`
pengyou
7th March 2010 00:50 UTC
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
SteveRussell
7th March 2010 13:04 UTC
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.