Dec 22, '09 07:30:01AM • Contributed by: luomat
I wrote a zsh function which will replace rmdir and do exactly that. It is also available as a bash script, which you can rename to rmdir and drop in your $PATH.
The code is thoroughly documented for anyone who wants to see how it works, but the executive summary is this:
- Take a bunch of arguments
- Check to see if those arguments translate to directories
- If they do, check to see if the directory is emptied by /bin/rmdir
- If /bin/rmdir fails, check to see if the only file in the folder is .DS_Store
- If yes, delete the file and re-run /bin/rmdir on the folder
- If no, just report the directory is not empty
