Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 15th April 2009, 11:53   #1
kmudrovcic
Junior Member
 
Join Date: Apr 2009
Posts: 25
How to remove only empty folder using IfFileExists function?

Hi,

I am trying to write an uninstall part where i remove empty folder and i bumped to a solution using IfFileExists but i don't know what am i doing wrong. Here is my code:

IfFileExists "$SMPROGRAMS\${company}\*.*" StartMenuIsntEmpty StartMenuIsEmpty
StartMenuIsEmpty:
MessageBox MB_OK "$SMPROGRAMS\${company} is empty"
RMDir /r /REBOOTOK "$SMPROGRAMS\${company}"
GOTO EndOfCheckIfStartMenuIsEmpty
StartMenuIsntEmpty:
MessageBox MB_OK "$SMPROGRAMS\${company} isn't empty"
EndOfCheckIfStartMenuIsEmpty:

So what's wrong in my code? I want to check if $SMPROGRAMS\${company} is empty and if it is, that i want to delete it.

Tnx in advance


Kresimir
kmudrovcic is offline   Reply With Quote
Old 15th April 2009, 12:39   #2
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
http://nsis.sourceforge.net/Check_if_dir_is_empty
Animaether is offline   Reply With Quote
Old 15th April 2009, 12:46   #3
kmudrovcic
Junior Member
 
Join Date: Apr 2009
Posts: 25
Tnx. :-)
kmudrovcic is offline   Reply With Quote
Old 15th April 2009, 12:52   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Birmingham, England
Posts: 8,202
Just use RMDir without the /r switch to delete a folder only if it is empty.

Stu

Need an installer? http://www.afrowsoft.co.uk
Afrow UK is offline   Reply With Quote
Old 15th April 2009, 13:11   #5
kmudrovcic
Junior Member
 
Join Date: Apr 2009
Posts: 25
i thought that RMDir /r means remove directory recursively. Are you sure that RMDir /r will remove only empty folder(s)?
kmudrovcic is offline   Reply With Quote
Old 15th April 2009, 14:05   #6
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
no, he means -without- /r.

I.e.

code:

RMDir "c:\temp"


will only remove the "c:\temp" folder if it is empty.

That's the default behavior, but it's not really appropriate for detecting whether it is or is not empty -before- an RMDir command (you'd have to check whether RMDir worked or not and if it did work.. depending on your code.. re-create it.. blurgh; hence that other function)
Animaether is offline   Reply With Quote
Reply
Go Back   Winamp 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