Thanks for pointing me in the right direction guys. I just finished the script (yeah it took me awhile, doing tech support sux0rs). Here is what I came up with, it's got some PM code in it along with mine. This was a quick hack to get it to do exctaly what I wanted, maybe the infinate wisdom of the Monks can clean it up some.
#!/usr/bin/perl
use strict;
use File::Find;
my $dir = shift;
if (!$dir) {die "perl $0 [startdir]\n";}
my @subdirs = ();
my $subdirsRef = \@subdirs;
my %size;
&get_sub_dirs($dir, $subdirsRef);
for my $foo (@subdirs) {
$size{$foo} = (&dir_tree_size($foo));
}
print "Subdirectory size report for $dir\n\n\n";
foreach my $key (sort keys %size) {
print "$key = ";
printf("%.3f", $size{$key});
print " K\n";
}
print "\n\n";
sub get_sub_dirs {
my ($dir, $arrayRef) = @_;
opendir DIR, $dir;
my @files = grep !/^\.\.?$/, readdir DIR;
for my $i (@files) {
if (-d $i) {
push @$arrayRef, $i;
}
}
}
sub dir_tree_size {
my $dir = shift;
my ($i,$total);
$total = 0;
opendir DIR, $dir;
my @files = grep !/^\.\.?$/, readdir DIR;
for $i (@files) {
if(-d $dir . "\\" . $i) {
$total += &dir_tree_size($dir . "\\$i")
} else { $total += -s $dir . "\\" . $i}
}
$total = $total / 1024;
return $total;
}
|