Redmine#6331: Skip non-empty directories silently when recursively deleting

The last commit fixes Redmine#6331, by skipping non-empty directories silently when recursively deleting. The rest are only making the code easier to digest.
Isn't this in case the path is specified as ``/etc/mydir/.``? I could still see that being the case, although whether that ever gets passed to this piece of code I don't know.