Just thought I'd share a small script that I use to rename my downloaded mp3 files. I like such files to have a consistent naming style - so running this script helps a little with this (tho i still make a manual pass).
It's very simple, and nothing amazing code-wise - but I find it useful :)
my $dir = './'; opendir(DIR, $dir) || die "Can't open $dir: $!"; my @files = readdir DIR; closedir DIR; my $n; # new name for file foreach $f (@files) { $n = lc $f; # convert to lower case $n =~ tr/_\{\}\[\]/ /; # get rid of certain brackets while ($n =~ / /) {$n =~ s/ / /g;} # remove double quotes $n =~ s/\s*.\s*/./g; # dots should have no white space $n =~ s/^\s*\d+\s*//g; # remove starting numbers $n =~ s/^\s*\W+\s*//g; # remove starting non-words if ($n =~ m/^\s*(.*)\w*$/g) {$n = $1}; $file_exists = (($n ne lc $f) && (-e $n)); if ($f ne $n && !$file_exists) {rename $f, $n;} }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: renaming multimedia files
by tadman (Prior) on Jul 03, 2001 at 08:40 UTC | |
|
Re: renaming multimedia files
by agent00013 (Pilgrim) on Jul 03, 2001 at 18:21 UTC |