#!/usr/bin/perl -l
use strict;
use warnings;
use File::Find;
@ARGV=grep {-d or !warn "'$_': not a directory!\n"} @ARGV;
die "Usage: $0
[]\n" unless @ARGV;
opendir(DIR1, $ARGV[0]);
my @subdirs = grep { !/^\.\.?$/ } readdir(DIR1);
closedir(DIR1);
my ($tot,$n,$f,$dcount,$fcount,$totfull)=(0,0,0,0,0,0);
for (@subdirs) {
$_ = $ARGV[0] . "/" . $_;
if (-f) {
$f++;
$totfull += -s;
#print $_;
}
elsif (-d) {
$dcount = 0;
$fcount = 0;
$tot = 0;
find { no_chdir => 1,
wanted => sub {
#return unless -f;
if (-d) {$n++; $dcount++;}
elsif (-f) {
$f++;
$fcount++;
#print "$f\n";
$tot += -s;
$totfull += -s;
#($max,$maxsz)=($_,$sz) if $sz >= $maxsz;
}
} }, $_;
die "Found 0 files\n" unless $f;
$dcount--;
print <<"EOF";
Total files found in $_ : $fcount
Total directories found in $_ : $dcount
Total size: $tot
EOF
}
}
print <<"EOF";
====================================
Directory Stats for $ARGV[0]
====================================
Total files found in $ARGV[0] : $f
Total directories found in $ARGV[0] : $n
Total size: $totfull
EOF