1) Presuming you'll be running this more than once, using a hash in the sense you're implying may not help. Since existing albums directories will be present, you need to check for their existence anyway before trying to create them. That can be done with the filetest -d, which implicitly checks for existence as well directory-ness. Just test the directory's existence before attempting to create it each time.

Using a hash for the files that you *are* moving might speed up your program if you have many tracks going into the same directory, but you'd be lucky to see an improvement, even in a benchmark. Besides, speed doesn't appear to be your primary concern here.

Also, where are you getting the album information? Your snippet doesn't get it, though MP3::Info allows you to retrieve it from the same hashref.

2) This sounds more like a design problem than a Perl problem. You need to decide whether you want to sort tracks based on album or artist. Personally, I sort my MP3s by artist then album (i.e. two dirs deep). And yes, soundtracks are difficult. I just have a Soundtrack directory and a directory under that for each movie title.

Perhaps this (untested) code will help get you on track.

#!/usr/bin/perl -w use strict; use MP3::Info; use File::Copy; use File::Find; use File::Basename; find(\&wanted, "/MP3"); sub wanted { /\.mp3$/ or return; my $tag = &MP3::Info::get_mp3tag($File::Find::name,1,1); my $artist = $tag->{ARTIST}; my $album = $tag->{ALBUM}; $artist |= "Unknown Artist"; $album |= "Unknown Album"; $artist =~ s/ /\\ /g; $album =~ s/ /\\ /g; my $dir = $File::Find::dir; -d "$artist" or mkdir "$dir/$artist" or die "Couldn't create $dir/$artist: $!"; -d "$artist/$album" or mkdir "$dir/$artist/$album" or die "Couldn't create $dir/$artist/$album: $!"; move $File::Find::name, "$dir/$artist/$album"; }

In reply to Re: MP3 Mover script by athomason
in thread MP3 Mover script by LoneRanger

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.