#!/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" +; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: more renaming! (mp3s) (now with File::Find!)
by grinder (Bishop) on Jul 18, 2001 at 00:55 UTC | |
|
Re: more renaming! (mp3s)
by spm (Acolyte) on Jul 18, 2001 at 14:13 UTC | |
by strfry() (Monk) on Jul 19, 2001 at 19:30 UTC | |
by Hofmator (Curate) on Jul 19, 2001 at 20:52 UTC | |
by strfry() (Monk) on Aug 16, 2001 at 00:47 UTC |