Old 12th June 2006, 12:38   #1
BashLogic
Junior Member
 
Join Date: Jun 2006
Posts: 8
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
BashLogic is offline   Reply With Quote
Old 12th June 2006, 13:38   #2
iceman_k
NSIS Dev
 
iceman_k's Avatar
 
Join Date: Feb 2003
Location: Boston, MA, U.S.A.
Posts: 455
Re: NSIS Check if directory exists

Quote:
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.

Cheers,
Iceman_K

EclipseNSIS - An NSIS IDE for the Eclipse Platform | My contributions to the wiki
iceman_k is offline   Reply With Quote
Old 12th June 2006, 15:48   #3
BashLogic
Junior Member
 
Join Date: Jun 2006
Posts: 8
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
BashLogic is offline   Reply With Quote
Old 12th June 2006, 16:37   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
IfFileExists "$INSTDIR\directory\*.*" ...

-Stu
Afrow UK is offline   Reply With Quote
Old 12th June 2006, 17:14   #5
iceman_k
NSIS Dev
 
iceman_k's Avatar
 
Join Date: Feb 2003
Location: Boston, MA, U.S.A.
Posts: 455
Quote:
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:

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

Cheers,
Iceman_K

EclipseNSIS - An NSIS IDE for the Eclipse Platform | My contributions to the wiki
iceman_k is offline   Reply With Quote
Old 19th June 2009, 13:01   #6
kekc
Junior Member
 
Join Date: Jun 2009
Posts: 6
Is there a way to know is it a file or directory?
kekc is offline   Reply With Quote
Old 19th June 2009, 13:37   #7
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Did you miss my code?

Same idea but using LogicLib:
code:
${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
Afrow UK is offline   Reply With Quote
Old 19th June 2009, 13:43   #8
kekc
Junior Member
 
Join Date: Jun 2009
Posts: 6
Thanks for the answer!

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

Good luck!
kekc is offline   Reply With Quote
Old 19th June 2009, 14:37   #9
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Why use that when you can just use the simple logic I gave?

Stu
Afrow UK is offline   Reply With Quote
Old 23rd June 2009, 07:01   #10
kekc
Junior Member
 
Join Date: Jun 2009
Posts: 6
First I thought, that empty dir will be detected as file.
But then I trieed everything is OK.

Thank you so much!
kekc is offline   Reply With Quote
Old 23rd June 2009, 14:08   #11
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 6th March 2010, 20:20   #12
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
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*\*.*`
SteveRussell is offline   Reply With Quote
Old 6th March 2010, 23:50   #13
pengyou
Major Dude
 
Join Date: Mar 2003
Posts: 571
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
pengyou is offline   Reply With Quote
Old 7th March 2010, 12:04   #14
SteveRussell
Senior Member
 
Join Date: Mar 2006
Location: United States
Posts: 109
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.
SteveRussell is offline   Reply With Quote
Old 12th February 2015, 07:29   #15
williamholdin
Junior Member
 
Join Date: Feb 2015
Posts: 1
Try this one...Directory Exisy

William
williamholdin is offline   Reply With Quote
Old 12th February 2015, 10:09   #16
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Quote:
Originally Posted by williamholdin View Post
Try this one...Directory Exisy

William
That is .NET (C#) code, not NSIS. Not sure why you have posted that.

Stu
Afrow UK is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump