roXet has asked for the wisdom of the Perl Monks concerning the following question:
Am I on the right track? Any suggestions are greatly appreciated.#!/usr/bin/perl use strict; my $dir = '.'; my %directories = (); my $dirsRef = \%directories; &find_size($dir, $dirsRef); foreach my $key (sort keys %directories) { print "$key has $directories{$key} bytes in it\n"; } sub find_size { my ($currentDir, $dirsRef) = @_; opendir DIR, $currentDir; my @files = grep !/^\.\.?$/, readdir DIR; for my $blah (@files) { if (-d $blah) { &find_size($blah, $dirsRef); } else { $dirsRef->{$currentDir} += (-s $blah); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Find the size of sub dirs
by Fastolfe (Vicar) on Feb 10, 2001 at 02:38 UTC | |
by roXet (Initiate) on Feb 10, 2001 at 04:52 UTC | |
by Fastolfe (Vicar) on Feb 10, 2001 at 22:39 UTC | |
by roXet (Initiate) on Feb 12, 2001 at 09:17 UTC | |
|
Re: Find the size of sub dirs
by runrig (Abbot) on Feb 10, 2001 at 03:15 UTC | |
|
Re: Find the size of sub dirs
by spaz (Pilgrim) on Feb 10, 2001 at 05:30 UTC | |
by roXet (Initiate) on Feb 10, 2001 at 05:42 UTC | |
by runrig (Abbot) on Feb 10, 2001 at 05:52 UTC |