Hiyis,

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
    To make this more general purpose, what about taking a list of MP3 files and either:
    • Rename files with ID3 tags according to the contents of their ID3 tags
    • Tag untagged files according to the contents of the filename
    Once tagged, you could twig the names, file into directories, etc.

    Also, watch out. The use strict Police are being dispatched to your location.
Re: renaming multimedia files
by agent00013 (Pilgrim) on Jul 03, 2001 at 18:21 UTC
    I've always wanted to take a stab at a script like this, but I haven't gotten around to it yet. You've got a good start. This script is good for clearing out junk text in the filename, but in it's current form it isn't capable of renaming to standard MP3 naming techniques such as Artist - Filename or of even determining this information. Some other scripts you might want to look at are available in the Audio : MP3 section at CPAN.