Archive: RMDir not working as expected


RMDir not working as expected
I did some searches to try to find an answer to a problem that I was having, but no luck.

I want to conditionally delete an installtion directory if and only if it's empty. IfFileExists does not work well for me, because .. and . are returned and the directories are not deleted, although empty.

I saw a tip saying to just use RMDir, and it will delete if the directory is empty. However, on my version (1.98) it is deleting everything in SUBDIRECTORIES and the directory itself.

How do I get out of this mess? Thanks in advance.


Are you sure you are using RMDir and not RMDir /r ?


Yes, that's what threw me. I have some occurences of other included files with RMDirs. I'm going to double check that there are no /r switches, btu I don't think there are.

If I'm the only one that's noticed this, it must be user error.


Yup. My Bad. An include file was doing it. I will be very careful with /r in the future.

As a side note, it would be an excellent idea to document the behavior of the RMDir command (/ifempty is the default). Besides it was not immediately apparent that the "recursive" terminology meant that unempty folders (especially root) would be deleted.

Here's the Windows RMDir help, which states this behavior. You command is analogous, but the docs don't mention the file deletions.

RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path

/S Removes all directories and files in the specified directory
in addition to the directory itself. Used to remove a directory
tree.


Done :D


Thanks for all your help! :)