http://qs1969.pair.com?node_id=168976


in reply to Using stat() to get the total size of files in a folder

How about:

use File::Find; my $size = 0; find(sub { $size += -s if -f $_ }, "foo");

That will recurse down into subdirectories. If that's not what you want, you could use:

use File::Find; my $size = 0; find(sub { $size += -s if $File::Find::name eq "foo/$_" and -f $_}, "f +oo");

-sam

Replies are listed 'Best First'.
Re: Re: Using stat()
by neilwatson (Priest) on May 24, 2002 at 13:34 UTC

    Sam has it right. File::Find is very fast and efficient. You can see a good example on my website

    Neil Watson
    watson-wilson.ca
      Ok, I've decided to use File::Find. When I call the find() function, I get this error.Insecure $ENV{PATH} while running with -T switch at /usr/lib/perl5/5.6.1/Cwd.pm line 92.So, I decided to add $ENV{PATH} = '/bin:/usr/bin'; to my script. Now, I'm getting this error.Insecure dependency in chdir while running with -T switch at /usr/lib/perl5/5.6.1/File/Find.pm line 467.I noticed in Neil's script, It didn't have the -T switch. Will File::Find just not run in taint mode?

      Thanks.
      Joshua