Ouch... that was foolish of me. Thanks!

In addition, the fact that I wasn't checking for errors on the rename operation allowed me to get away with not seeing a couple serious logic errors: this script occasionally attempts to rename files it has already deleted in addition to trying to rename the "." and ".." directory entries.

Updated code follows:

#!/usr/bin/perl -w # 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\n"; print "more Internet friendly by renaming files and directories in\n"; print "a more appropriate manner. Running it on a directory other\n"; print "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 ".") || ($_ eq "..")) { return 0; } if ($_ eq ".DS_Store") { unlink $_; return 0; } elsif ($_ eq ".FBCIndex") { unlink $_; return 0; } elsif ($_ eq ".FBCSemaphoreFile") { unlink $_; return 0; } elsif ($_ eq ".FBCLockFolder") { rmdir $_; return 0; } else { my $original_filename = $_; s/\'//g; s/\,//g; s/\#//g; s/&/and/g; s/!//g; s/\(//g; s/\)//g; s/ /_/g; $_ = lc($_); if (-e) { warn "Cannot rename $original_filename to $_: file exists\ +n"; } elsif (!rename($original_filename, $_)) { warn "Cannot rename $original_filename to $_: $!\n"; } return 0; } }

In reply to Re: &bull;Re: Cleaning up an iTunes music collection by mvaline
in thread 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.