Check directory is empty before removal.
Improved error checking in rmdir.