kmudrovcic
15th April 2009 12:53 UTC
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
15th April 2009 13:46 UTC
Tnx. :-)
Afrow UK
15th April 2009 13:52 UTC
Just use RMDir without the /r switch to delete a folder only if it is empty.
Stu
kmudrovcic
15th April 2009 14:11 UTC
i thought that RMDir /r means remove directory recursively. Are you sure that RMDir /r will remove only empty folder(s)?
Animaether
15th April 2009 15:05 UTC
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)