#!/usr/bin/perl use File::Find; use File::Basename; my %tree = (); my $adur = 0; my $scandir = shift(@ARGV); $scandir =~ s/\\/\//g; $scandir = '.' if not $scandir; find( { wanted => \&fproc, postprocess => \&dproc, bydepth => 1 }, $scandir); sub fproc() { if (m/\.(wav|mp3)$/i) { my $ms = qx("C:/utils/mediainfo/mediainfo.exe" --Inform='Audio;%Duration%' "$File::Find::name"); if (($? >>=8) != 0) { die "Failed to run mediainfo on $File::Find::name"; } else { #print "$File::Find::name duration $ms ms\n"; $adur += $ms/1000; } } } sub dproc() { my $path = $File::Find::dir . '/'; my ($dir, $parent) = fileparse($File::Find::dir); $tree{$path}{':total:'} += $adur; $tree{$parent}{':total:'} += $adur; print "$path: $tree{$path}{':total:'} s\n"; $adur = 0; }