i had a simple need: the folders of my music libary have been cluttered with old
albums, that had been moved or deleted, but whose folders remained because they
still had cover.jpg
or AlbumArtSmall.jpg
or the like left behind. i wanted
these folders gone; they had no use remaining. iTunes would not see these folders
(though all of these deletions/moves occurred under iTunes' watch, so you'd think
it'd move the images as well *shrug*) so i took matters into my own hands.
this script searches the directory structure, starting in the current working
directory. called with no arguments, it will print folders that match my definition
of "empty": contain no subdirectories, nor any files that end in .mp3
, .m4a
,
or .wav
. it also prints their contents, so you can see what files have kept these
folders in existence.
if you run it with the -y
flag, though, it will delete the folders in question,
along with the files that remained.
this script may need to be run multiple times, in case there were several "empty" folders layered within each other.
here's an example run:
$ music-clean.sh
music-clean.sh : if run with -y, this will delete directories that don't have music files in them.
(when run without, simply prints directories slated for deletion, and their contents, for verification.)
you have been warned. please use with caution. this starts in your current directory.
basing search in '/mnt/winhdd/Users/Bryan/Music/iTunes/iTunes Music/Music...'
press Enter to continue...
/mnt/winhdd/Users/Bryan/Music/iTunes/iTunes Music/Music/Andrew Huang/Suture Sound
Folder.jpg
/mnt/winhdd/Users/Bryan/Music/iTunes/iTunes Music/Music/Andrew Huang & Boyinaband/Suture Sound
Folder.jpg
/mnt/winhdd/Users/Bryan/Music/iTunes/iTunes Music/Music/Billy Joel/The Complete Hits Collection
AlbumArtSmall.jpg
Folder.jpg
/mnt/winhdd/Users/Bryan/Music/iTunes/iTunes Music/Music/Daft Punk/Homework
AlbumArtSmall.jpg
Folder.jpg
/mnt/winhdd/Users/Bryan/Music/iTunes/iTunes Music/Music/Masashi Hamauzu/Final Fantasy XIII Original Soundtrack
AlbumArtSmall.jpg
Folder.jpg
/mnt/winhdd/Users/Bryan/Music/iTunes/iTunes Music/Music/OverClocked ReMix & The Shizz/Final Fantasy_ Random Encounter
Folder.jpg
/mnt/winhdd/Users/Bryan/Music/iTunes/iTunes Music/Music/Unknown Artist/Unknown Album
/mnt/winhdd/Users/Bryan/Music/iTunes/iTunes Music/Music/Various Artists/The Matrix Revolutions
AlbumArt_{8E5104FB-C953-4928-9EDD-8BEA30714AE4}_Large.jpg
AlbumArt_{8E5104FB-C953-4928-9EDD-8BEA30714AE4}_Small.jpg
AlbumArtSmall.jpg
Folder.jpg