#!/usr/bin/perl -w use strict; use File::Find; # find() calls the wanted subroutine for each file and directory # underneath the starting point(s) (can specify more than one # directory tree to traverse down) find(\&wanted, "C:/temp"); # within subroutine "wanted": # use these variables to figure out where you are: # $File::Find::dir is the current directory name, # $_ is the current filename within that directory # $File::Find::name is the complete pathname to the file. # wanted() cannot return anything directly # declare a data struct at a higher scope that this sub # writes to my %mailboxesWithMessages; my %allMailboxes; sub wanted { #full path must contain a mailbox number my $mbox; return() unless ( ($mbox) = $File::Find::name =~ /(\d+)\@/); if (-d $File::Find::name) #some mbox may have no .msg files { $allMailboxes{$mbox}=1; return; } #must be looking at a messsage file return() unless ( -f _ and $File::Find::name =~ /\.msg$/); my $size = -s _; $size = 4096 if $size < 4096; $mailboxesWithMessages{$mbox}+= $size; # comment out above and run this sub with just this line to # see what it does... # print "$File::Find::name\n"; return; }