I'm trying to write some ruby that would recursively search a given directory for all empty child directories and remove them.
Thoughts?
Note: I'd like a script version if possible. This is both a practical need and a something to help me learn.
I'm trying to write some ruby that would recursively search a given directory for all empty child directories and remove them.
Thoughts?
Note: I'd like a script version if possible. This is both a practical need and a something to help me learn.
I've tested this script on OS X, but if you are on Windows, you'll need to make changes.
You can find the files in a directory, including hidden files, with Dir#entries.
This code will delete directories which become empty once you've deleted any sub-directories.
For a pure shell solution, I found this very useful
But if you have gnu-find installed (not universal yet)...
this uses find with xargs...
Why not just use shell?
Does exactly what you want.
You have to delete in reverse order, otherwise if you have an empty directory foo with a subdirectory bar you will delete bar, but not foo.