HelluvaEngineer
28th October 2002 20:47 UTC
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.
Joost Verburg
28th October 2002 22:27 UTC
Are you sure you are using RMDir and not RMDir /r ?
HelluvaEngineer
29th October 2002 13:45 UTC
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.
HelluvaEngineer
29th October 2002 18:53 UTC
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.
Joost Verburg
29th October 2002 19:52 UTC
Done :D
HelluvaEngineer
29th October 2002 21:12 UTC
Thanks for all your help! :)