in reply to looking for simple solution

Try this:

my $dir = "//home//schmoe//somedir"; my $dirsize = -s $dir || die "can't stat dir $dir: $!";

It should work. Any other ideas?

Update:

for those of us with real operating systems:

`du -ks`
works just fine.

Update #2:

I found this in the Perl Cookbook, and made it a standalone bit of code:

#!/usr/bin/perl -w use strict; use File::Find; @ARGV = ('.') unless @ARGV; my $sum = 0; find sub { $sum += -s }, @ARGV; print "@ARGV contains $sum bytes\n";

This should be the ticket.

J. J. Horner
Linux, Perl, Apache, Stronghold, Unix
jhorner@knoxlug.org http://www.knoxlug.org/

Replies are listed 'Best First'.
RE: Re: looking for simple solution
by SuperCruncher (Pilgrim) on Jun 16, 2000 at 14:03 UTC
    JJ, out of curiosity, why did you do:
    my $dir = "//home//schmoe//somedir";

    (i.e. the double slashes?) The only place where I've found this appropriate is when using paths in the DOS/Win32 format, as obviously if you did c:\noddy if a double-quoted string, Perl looks for a dir named 'c: linebreak oddy'.

    Is there something I don't know about here? BTW Win32 users - you can use the UNIX-style slashes when telling Perl to open files etc! I far prefer / to \!