filenametag.pl (745B)
1 #!/usr/bin/perl 2 use File::Basename; 3 use File::Copy; 4 use MP3::Tag; 5 6 print "Filename Change according to TAG in mp3s <dsp@2f30.org>\n"; 7 $num_args = $#ARGV + 1; 8 if ($num_args != 1) { 9 print "\nUsage: filenametag.pl dir\n"; 10 die; 11 } 12 13 $dir = $ARGV[0]; 14 print ":Opening Dir:\n"; 15 opendir(DIR, $dir) or die "can't opendir $dir: $!\n"; 16 while (@files = grep { /.mp3/ } readdir(DIR)){ 17 foreach $file (@files){ 18 $fname = $dir.'/'.$file; 19 my $mp3 = MP3::Tag->new($fname); 20 ($title, $artist, $no, $album, $year) = $mp3->autoinfo(); 21 print "$title"; 22 if($file =~ m/$title/i){ 23 print "\nall ok\n"; 24 } 25 else{ 26 $newfname = $dir.'/'.$title.'.mp3'; 27 print "\ni will rename to $newfname!\n"; 28 move($fname,$newfname); 29 } 30 } 31 } 32 closedir(DIR);