in reply to Filesize counting recursive

Another way to do this would be to use the File::Recurse module from CPAN. Like so:
use strict; use File::Recurse; MAIN: { my $dir = $ARGV[0]; my $size = 0; recurse(\&sum_size, $dir, \$size); print "Total size: $size\n"; } sub sum_size { my ($file, $total_size_ref) = @_; stat($file); unless (-d _) { $$total_size_ref += -s _; } 1; }
There's something funky about the above... it produced larger values than crulx's code for a couple of my directories, reason unknown. Seemed fairly accurate, though...

Replies are listed 'Best First'.
RE: Re: Filesize counting recursive
by Crulx (Monk) on Jan 23, 2000 at 09:49 UTC
    Never heard of it. I cannot find it on CPAN either. Is is part of another File:: package?

    Crulx

      (Note: perl -MCPAN -e shell is WONDERFUL from the Unix command line)

      Here's the data I found on it:
      Module id = File::Recurse
      CPAN_USERID ASHER (Aaron Sherman <ajs@ajs.com>)
      CPAN_VERSION 1.0
      CPAN_FILE ASHER/File-Tools-2.0.tar.gz
      INST_FILE (not installed)