#!/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[mmp3\e[1;30m/\e[mdirectory \n\n"," " x 7, "Get rid of annoying characters out of files (spaces and single quotes)\n", " " x 7,"you \e[31mmust\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);closedir(DIR); opendir(DIR, "$cwd") or die "can't open $cwd: $! !\n"; my @skipped = grep { /^[\.].*\.mp3$/ && -f "$cwd/$_" } readdir(DIR);closedir(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"; } }