#!perl #Chris Uriarte #Looks through $basedir (your MP3 root directory) and goes into artist and album folders. #Renames the playlist in the album folder "Artist - Album.m3u" #Written for WindowsPCs...modify the directory backslashes to work on UNIX. $basedir = $ARGV[0] || die "useage: m3u.pl \n"; chdir($basedir) || die "Could not chdir to $basedir. Is it a valid path?\n"; #keep a counter of m3u files we encounter $number = 0; print "Getting list of artist directories\n"; @dirs = <*>; foreach (@dirs) { my $artist_dir = $_; my $artist_path = $basedir . '\\' . $artist_dir; chomp($artist_path); #print "Found artist $artist_dir\n"; #Now go into the artist directory; chdir($artist_path); my @albums_dir = <*>; foreach (@albums_dir) { my $album_dir = $_; chdir($artist_path); chdir($album_dir); chomp($album_dir); #Get the m3us @m3us = <*.m3u>; foreach(@m3us) { $number++; $playlist = $_; $artist_name = $artist_dir; #Get rid of the "The " in front of an artists name if ($artist_name =~ /^The /i) { print "Artist name $artist_name starts with The - getting rid of it for m3u filename\n"; $artist_name =~ s/The //; } $newname = "$artist_name-" . " $album_dir" . ".m3u"; chomp($newname); #system("$rename") or warn "rename failed for $rename"; $oldname = "$artist_path\\$album_dir\\$playlist"; $newname = "$artist_path\\$album_dir\\$newname"; #print "renaming $oldname to $newname\n\n"; rename $oldname, $newname || warn "********************Cannot rename: $!\n"; } #End of m3u loop } #end of album loop for this artist } #end artist directories loop print "Complete. Renamed $number playlists\n";