Archive: How to remove only empty folder using IfFileExists function?


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


http://nsis.sourceforge.net/Check_if_dir_is_empty


Tnx. :-)


Just use RMDir without the /r switch to delete a folder only if it is empty.

Stu


i thought that RMDir /r means remove directory recursively. Are you sure that RMDir /r will remove only empty folder(s)?


no, he means -without- /r.

I.e.


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)