It changes all mp3 names in the specified dir (. per default). I'm tired of those odd file names mp3 have on the internet. It strips some chars that i dislike (spaces, commas, quotes) and make everything lower case. Many people that I know found it very useful. I hope you'll too. :) I really want you to comment if there's something wrong (style) or if there's a better way to do something. I'm learning perl. (Changed)
use String::ShellQuote use Cwd; unless ($ARGV[0]) { $dir = getcwd; } else { $dir = $ARGV[0]; } unless ($dir =~ /[\/]$/) { $dir .= "/"; } opendir (DIR, $dir) or die $!; my @arquivos = grep /\.mp3$/i, readdir DIR; foreach my $mp3file (@arquivos) { $new_name = $mp3file; $new_name =~ s/\s+/_/g; $new_name =~ s/_-_/-/g; $new_name =~ s/^[-_]+//; $new_name =~ s/&/and/g; # & becomes "and" $new_name =~ s/[\(\)\[\]]+/_/g; # () and [] become _ $new_name =~ s/,/_/g; $new_name =~ s/[\'\"]+/_/g; # no quotes $new_name =~ s/\`+/_/g; $new_name =~ s/_+/_/g; $new_name =~ s/-+/-/g; $new_name = lc $new_name; # lowercase if ($new_name ne $mp3file) { $dir = shell_quote ($dir); $mp3file = shell_quote ($mp3file); $new_name = shell_quote ($new_name); system "mv $dir$mp3file $dir$new_name"; print "\n$mp3file became $new_name"; } } closedir DIR;

Replies are listed 'Best First'.
Re: rigthmp3names
by zentara (Cardinal) on Feb 20, 2005 at 11:03 UTC
    my @arquivos = grep /\.mp3/i, readdir DIR;

    Shouldn't that be

    my @arquivos = grep /\.mp3$/i, readdir DIR;
    just in case you have a filename like my.mp3.wav ?

    I'm not really a human, but I play one on earth. flash japh
Re: rigthmp3names
by Anonymous Monk on Feb 20, 2005 at 17:00 UTC
    just to get this out of the way because it's inevitable: use strict; use warnings; *mumble*groupthink*mumble*B&D*mumble*
Re: rigthmp3names
by Anonymous Monk on Feb 20, 2005 at 19:59 UTC

    Filenames are for humans. If they were not, we would refer to files by their FAT or inode number.

    Therefore, I want my filenames with proper spelling and punctuation, as far as the naming restrictions allow.

    Musicbrainz (on CPAN) have tools that recognise music files by their audio fingerprint, and update ID3 metainformation and filename.

      it's your choice to use it or not. :)