I use iTunes running on Mac OS X to create and manage my mp3 collection. It's a great piece of software, but it unfortunately doesn't give the user any control over the format of the filenames and directories it outputs. They consequently contain not only annoying characters like spaces, pound signs and parentheses, but also dangerous characters like ampersands, commas and apostrophes. I use this script to make my music directory a little more Internet friendly.
#!/usr/bin/perl # mp3clean: make an iTunes music collection more Internet friendly. # Micah Valine <micah@micahvaline.com> use strict; use File::Find; die "Usage: mp3clean [Music Root Directory]\n" unless @ARGV == 1; my $start_directory = $ARGV[0]; print "\nmp3clean is designed to make an iTunes music collection more +Internet friendly\n"; print "by renaming files and directories in a more appropriate manner. + Running it on a directory\n"; print "other than a directory of mp3's may cause permanent damage.\n\n +"; print "Press Enter to run mp3clean on [$start_directory]. "; my $user_response = <STDIN>; finddepth(\&cleanup, $start_directory); print "\nmp3clean complete!\n"; sub cleanup() { # get rid of these annoying files while we're at it if ($_ eq ".DS_Store") { unlink $_; } if ($_ eq ".FBCIndex") { unlink $_; } if ($_ eq ".FBCSemaphoreFile") { unlink $_; } if ($_ eq ".FBCLockFolder") { rmdir $_; } my $original_filename = $_; s/\'//g; s/\,//g; s/\#//g; s/&/and/g; s/!//g; s/\(//g; s/\)//g; s/ /_/g; $_ = lc($_); rename($original_filename, $_); }

In reply to Cleaning up an iTunes music collection by mvaline

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.