This is almost too easy. I recently ripped some of my CD's into MP3's with my favorite ripper/encoder, grip. I was so busy feeding it Radiohead CD after CD that i forgot to move the newly encoded MP3's to their final destination before the next batch was ripped/encoded. The end result was a directory structure similar to:

mp3
---radiohead
   ---100395
      ---01-you.mp3
   ---132557
      ---02-creep.mp3
   ---168860
      ---01-planet_telex.mp3
   (etc.)
   ---pablo_honey
   ---the_bends
Each MP3 file was stored in one of those '168860' directories and nothing was inside the directories that are actually named after the album titles. On top of that, i did not know offhand which album that '168860' belongs to. Normally i rip/encode one CD and then move the MP3's - now i have to move each file one at a time to it's proper album/directory and i have to manually look each one up by scanning the CD with my eyes/brain. Ughh ... that could take 30 minutes! (time better spent watching the Simpsons!)

The quick fix? First, move all MP3 files to inside the 'parent' directory (radiohead).


[jeffa@trinity radiohead]# mv */*.mp3 .
Second, run this script:
use MP3::Info; for my $file (<*.mp3>) { my $id3 = get_mp3tag($file); my $dir = lc $id3->{ALBUM}; $dir =~ tr/ /_/; system mv => $file => $dir; }
Much quicker. ;)

UPDATE: added Aristotle's improved alternative to backticks. Very nice. :) Oh, and as he says, this only works if your MP3's are properly tagged. Since they came straight from grip ... mine were. ;)

Also, i probably should have used zakzebrowski's suggestion, but it is trivial enough to change that i will leave the code untouched. (see his comment below).

OH YEAH: PodMaster says "CDex for yer win32"

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Move MP3 files to proper dirs by jeffa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.