# # Copies MP3s by genre tag using sources directory tree. # Script must be executed from the source's root # i.e. $srcdir must be a path on the same drive as where the script is executed from # # Criticism/advice appreciated # use strict; use MP3::Info; use File::Find; use File::Copy; use File::Basename; use File::Path; my $genre = 'Country'; my $srcdir = '/MP3 Test/'; my $dstdir = 'c:/'; my ($tag, $newdir, $path, $file, $dir); find(\&wanted, $srcdir); sub wanted { open(FL, $File::Find::name); if ((/\.mp3/)){ $tag = get_mp3tag($_) or print "Could not access tag on $_\n" and next; if ($tag->{"GENRE"} eq $genre) { $path = $File::Find::name; $dir = dirname($path); $file = basename($path); $newdir = $dstdir . $dir; if (! -d $newdir ) { mkpath ($newdir, 0666) || die "can't mkdir $newdir: $!\n"; } copy($path, $newdir . '/' . $file) or die "copy failed: $!\n"; } } close(FL); }