Find or Delete Empty Folders

Hello.

Is there a way to automate the finding and/or deleting of empty folders?

I just transferred my music collection to a new computer and didn't uncheck the option to have iTunes organize for me and now I have a lot of empty folders that I need to delete.

I have a very large mp3 collection (99% legal) and this will take days to rectify.

Thanks, in advance, for any replies.

-Tut-

Mac OS X (10.4.6)

Posted on Jun 23, 2006 7:03 AM

Reply
12 replies

Jun 23, 2006 11:36 AM in response to Mekonnen

I have a Saved Search that does this. Navigate to the folder whose sub-folders you want to search. In the first drop-down criterion select Kind: Folders. In the second select "Other..", then in the window listing that appears scroll down to "Number of items", select it, then from its drop down option select Less than: 1. For some reason the obvious thing of selecting Size for the second criterion doesn't work....one of the mysterious little glitches of Spotlight.
Francine

User uploaded file
Francine
Schwieder

Jun 23, 2006 9:00 AM in response to Mekonnen

If the folders are truly empty, then something like this should work (entered using "/Applications" > "Utilities" > "Terminal.app"):<pre>find /path/to/main/folder -type d -print0 |xargs -0 rmdir 2>/dev/null</pre>However, folders on Macs often contain invisible items like ".DS_Store" files whose presence would block the 'rmdir' command which, as written, will only work on completely empty directories (if you don't mind deleting all ".DS_Store" folders within the main folder prior to deleting "empty" folders, that might be an option). Also, if a folder contains only an empty folder, the command will remove the inner folder, but won't necessarily remove the outer folder which would now be empty - ie. multiple runs may be necessary...

Jun 23, 2006 9:50 AM in response to macjack

WIW, I haven't been able to do this with Automator. It is easy enough to "Find Finder Items" that are folders but adding a size criteria to the action always returns no results, apparently because the action's size criteria only applies to files, not folders. Likewise, the "Filter Finder Items" action has no suitable filters for size.

If one is handy with AppleScript, it would be easy enough to automate this, but Automator alone doesn't seem up to the task.

Jun 23, 2006 5:01 PM in response to Mekonnen

I think we're close... I tried it and if found about 27 empty folders (and I would think I will end up with, like... 300? I don't really know.

When I did a search for 'less than 2' instead of 'less than 1' I got a much more accurate response. I'll assume that's the .DS_Store mentioned earlier. My question is: after I spot check a few files to make sure they're empty, would I be safe to delete? Does every folder require a .DS_Store... is it likely that a file would exist in a folder without a .DS_Store?

Thank you everyone... I really appreciate the assistance, 'cause I was looking at a lot of time doing this manually... to make matters worse, it's on a Mac Mini feeding a regular Television, so the resolution is painful to work with.

Thanks again.

Jun 23, 2006 7:54 PM in response to Mekonnen

Not every folder has a .ds_store file. Ones never opened in Finder usually don't. You can see this by going to list view in folders you don't usually open, like in /Library. Flipping open a disclosure triangle for an "empty" folder with zero size & flipping it closed again will add 4 KB or more to the folder size, showing that the .DS_Store file has been created to hold Finder display info, even if there isn't much of it to store.

Jun 23, 2006 11:38 PM in response to Mekonnen

You can also put the search window into List View, then click on the Size column. Obviously all those that show Zero KB can be deleted. Just as obviously those that show MBs need to be saved. But what about all the 4 or 8 KB folders? How about 24KBs? I do have some sound files that are less 24KBs--I even have a few that are 8KBs and a couple that are 4KBs. They all are in the same folder though. You might do a search on your Music folder for Size: Less than: 24KBs and Kind: Music and see what turns up. Again, you can put the search window into list view and arrange by the size column.

is it likely that a file would exist in a folder without a .DS_Store?


Afraid so. Unless you've opened a folder in the Finder it doesn't have a .DS_Store file, and there are likely to be quite a few of the folder created by iTunes to organize your music that you've never actually opened.

Nothing really clever has occurred to me to auto search the results you get. Wouldn't it be nice if you could do a separate search of Spotlight results!
Francine

User uploaded file
Francine
Schwieder

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Find or Delete Empty Folders

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.