sub topdir { my($nd,$parent)=@_; my $d = $nd; # Hack; strip off trailing characters that might be directory # seperators $parent =~ s/\W$//; while ($nd ne $parent) { $d = $nd; $nd = File::Basename::dirname($d); } return $d; } #### #!/usr/bin/perl -w use strict; use File::Find; use File::Basename; our $dir = $ARGV[0]; find(\&do_dir, $dir); my %hash; sub do_dir { my $size = -s ($File::Find::name) or return; my $d = topdir($File::Find::dir,$dir); if (!defined($hash{$d})) { $hash{$d} = 0; } # warn "size=$size, d=$d\n"; $hash{$d} += $size; } foreach (keys %hash) { print "DIR $_ = $hash{$_}\n"; }