1: # 2: # Copies MP3s by genre tag using sources directory tree. 3: # Script must be executed from the source's root 4: # i.e. $srcdir must be a path on the same drive as where the script is executed from 5: # 6: # Criticism/advice appreciated 7: # 8: 9: use strict; 10: use MP3::Info; 11: use File::Find; 12: use File::Copy; 13: use File::Basename; 14: use File::Path; 15: 16: my $genre = 'Country'; 17: my $srcdir = '/MP3 Test/'; 18: my $dstdir = 'c:/'; 19: my ($tag, $newdir, $path, $file, $dir); 20: 21: find(\&wanted, $srcdir); 22: 23: sub wanted { 24: open(FL, $File::Find::name); 25: 26: if ((/\.mp3/)){ 27: $tag = get_mp3tag($_) or print "Could not access tag on $_\n" and next; 28: 29: if ($tag->{"GENRE"} eq $genre) { 30: $path = $File::Find::name; 31: $dir = dirname($path); 32: $file = basename($path); 33: $newdir = $dstdir . $dir; 34: 35: if (! -d $newdir ) { 36: mkpath ($newdir, 0666) || die "can't mkdir $newdir: $!\n"; 37: } 38: copy($path, $newdir . '/' . $file) or die "copy failed: $!\n"; 39: } 40: } 41: close(FL); 42: }
Back to
Craft