I want to extract values from music structure directories using File::Find::Rule and I’m having difficulties getting the total discs of each album if present, e.g if an album contains 3 subdirectories DISC1, DISC2, DISC3 – the total discs value should be 3. If I grep these directories before the “For” statement it gets the total of all found, and if I try within the “For” statement it counts one at a time. How to extract total discs for each album if present. Thanks.
use autodie;
use strict;
use warnings;
use File::Find::Rule;
use File::Spec;
my $dir = 'D:\Test';
$dir =~ s#\\#/#g;
my @fd = File::Find::Rule->directory()
->name( qr/\(\d+\)/ )
->in( $dir );
my $grep_totaldiscs = grep /DISC\d+/, @fd;
print "$grep_totaldiscs\n";
for my $fd ( @fd ) {
my ($genre, $artist, $album, $disc) = (File::Spec->splitdir($fd))[2..5];
my ($discnumber, $totaldiscs);
if ($fd =~ /DISC(\d+)/) {
$discnumber = $1;
$totaldiscs = $1 if ( defined($totaldiscs) < $1 );
print "$album $totaldiscs\n";
}
}
In outline:
I’ve used artist and album combined to disambiguate in the keys of the hash here.
For example: