i've had considerable trouble with playing other people's mp3s (notably, those written with spaces and single quotes (').. so i wrote a small script that will rename an entire directory (but not subdirectories, yet (: ) full of mp3s, to where they're easier on the command-line completion. eg. "some file's desperate attempt at proper grammar.mp3" becomes "some_files_desperate_attempt_at_proper_grammar.mp3"
this is for all you slow/lazy typers out there. (:

PS: if someone can add recursiveness to this script, i'd be very thankful (i haven't had the time); also, i made it to where it wouldn't rename 'hidden' (leading dot) files, as a feature. (due to certain programs saving incomplete files with leading dots)
Update: Fixed broken code (for for ignoring hidden files) Update 2: posting it to code catacombs, it grew too big with recursiveness to really be considered a snippet. (hehe, and this started with a one-liner.)
#!/usr/bin/perl -w use strict; # or die $! (8 use Getopt::Std; use vars qw/$opt_h/; getopts('hr'); $0=~s|.*[/\\]||; my($arg) = $ARGV[0] if ($ARGV[0]); &usage if ((!$ARGV[0]) || ($opt_h)); &usage if($opt_h); &simple_rename($arg); sub usage { die "usage\e[1m:\e[m $0 \e[1;30m/\e[mpath\e[1;30m/\e[mto\e[1;30m/\e[mm +p3\e[1;30m/\e[mdirectory \n\n"," " x 7, "Get rid of annoying characte +rs out of files (spaces and single quotes)\n", " " x 7,"you \e[31mmus +t\e[m have read\e[1;30m/\e[mwrite permission to directory!\n", " " x +7, "eg. $0 \e[1;34m~\e[m\e[1;30m/\e[mmp3s\e[1;30m/\e[m\n"; } sub simple_rename { my($cwd) = $_[0]; opendir(DIR, "$cwd") or die "can't open $cwd: $! !\n"; my @mp3s = grep { /^[^\.].*\.mp3$/ && -f "$cwd/$_" } readdir(DIR);clos +edir(DIR); opendir(DIR, "$cwd") or die "can't open $cwd: $! !\n"; my @skipped = grep { /^[\.].*\.mp3$/ && -f "$cwd/$_" } readdir(DIR);cl +osedir(DIR); chdir "$cwd" or die "couldn't cd to $cwd: $!\n"; foreach (@mp3s) { if ((/ /) or (/'/)){ my $old = $_; s/ /_/g; s/'//g; rename $old,$_; print "$old \e[31m->\e[m $_ \n"; } } foreach (@skipped){ print "skipped [\e[1;34m$_\e[m] due to leading dot. (\".\")\n" +; } }

In reply to more renaming! (mp3s) by strfry()

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.