in reply to Re: Find the size of sub dirs
in thread Find the size of sub dirs
If your behavior was a little simpler (relying on arguments instead of finding subdirs first):
Preserving the behavior of your script (mostly):use File::Find; use strict; foreach my $dir (@ARGV) { my $total; find(sub { $total += -s }, $dir); print "$dir: $total\n"; }
use File::Find; use File::Spec; use strict; my $cur = File::Spec->curdir; my $up = File::Spec->updir; foreach my $start (@ARGV) { my @dirs = &find_subdirs($start); foreach my $dir (@dirs) { my $total = 0; find sub { $total += -s }, $dir; printf "%-20s %d\n", $dir, $total; } print STDERR "$start: No subdirectories\n" unless @dirs; } sub find_subdirs { my $start = shift; unless(opendir(D, $start)) { warn "$start: $!\n"; next; } my @dirs = map { -d "$start/$_" && !-l "$start/$_" && $_ ne $cur && $_ ne $up ? "$start/$_" : () } readdir(D); closedir(D); @dirs; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Find the size of sub dirs
by roXet (Initiate) on Feb 12, 2001 at 09:17 UTC |