in reply to Faster way to obtain a remote share or folder size

Your headline asks for a faster way, but the message asks how you can get the size of a directory other than the one where you are.

Of course, I'm writing on Linux, but the routine should work on all platforms.

my $dirname = "/usr/local/bin"; my $size = get_dir_size( $dirname ); # Perl Cookbook recipe 9.5 # sub get_dir_size { return unless @_ && -e $_[0] && -d _ && -r _ ; my ( $dir ) = @_; my ( $file, $size ); opendir DIR, $dir or die( "Could not open directory '$dir'\n" ); while ( defined ( $file = readdir( DIR ))) { $size += -s "$dir/$file"; } closedir DIR; return $size; }

Of course, the easy answer, especially if you're interested in subdirectories, too, is:

$size = `du -s -k $dir`;

--
TTTATCGGTCGTTATATAGATGTTTGCA

Replies are listed 'Best First'.
Re: Re: Faster way to obtain a remote share or folder size
by blackadder (Hermit) on Jul 02, 2003 at 08:05 UTC
    Thanks guys, I 'll try out your suggestions...

    And I'll try and be more precise with wording of my posts :)

    Cheers.