This script reads in a list of mp3s (assumed to be in one directory) and organizes them into directories by artist/album. It first attempts to use the id3 tag, but if one is not found, it falls back to parsing the filename for the artist name. I use this script every so often because I download all my mp3s to one directory, and it gets cluttered quickly. The script doesn't have the desired results, however, if mp3s without id3 tags have a hyphen in the filename, but don't have the artist first (e.g., "ice ice baby - vanilla ice.mp3").

This is my first post, please feel free to offer comments/criticism. Thanks!

Update: I removed the system calls to /bin/mv and replaced them with calls to rename, after a tip from salvadors.

Thanks for the suggestion! I was curious as to whether rename would be faster, though, since it requires one call per mp3, whereas /bin/mv requires only one call per directory. After a quick scan of my collection, I made a conservative estimate of five mp3s per directory (meaning, of course, five times as many calls are required for rename as /bin/mv). The results of a benchmark, however, were enlightening. Here is the benchmarking code I used: