RE: Directory Size





> -----Original Message-----
> From: Nick [mailto:lists@xxxxxxxxxxx]
> Sent: Sunday, August 28, 2005 1:26 PM
> To: Perl Beginners
> Subject: Directory Size
>
> Hi All,
>
> Is there a way to get an entire directory and all
> sub-files/folders size in Perl? Basicly, I need the Perl
> version of "du -s".
>
> I've currently done it with stat but this only gives a
> directory size not taking into consideration everything inside it.
>
> Nick
>

Try this:


use File::Find;

my $dir = $ARGV[0];
my $size;

find( sub { -f and ( $size += -s _ ) }, $dir );






.



Relevant Pages

  • Re: Does Minimal Perl works for beginners?
    ... I am a Perl beginners, and I have heard about Minimal Perl. ... I've always been a big fan of _Learning Perl_ as a book to start with. ...
    (perl.beginners)
  • Re: specifying use strict
    ... > to teach myself Perl under time constraints. ... Acquaint yourself with the posting guidelines for ... Also, there are a number of good mailing lists for Perl beginners, ...
    (comp.lang.perl.misc)
  • RE: New to PERL and Need Help
    ... Read learning perl. ... Network Administrator ... > To: PERL Beginners ... On my home PC I have XP Prof. and Oracle 9.2. ...
    (perl.beginners)
  • Does Minimal Perl works for beginners?
    ... I am a Perl beginners, and I have heard about Minimal Perl. ... Or that 'flavour' of the language would work better for more advanced programmers. ...
    (perl.beginners)
  • RE: PERL on 9.2 and XP Prof.
    ... And use PPM to install cpan ... > To: PERL Beginners ... PERL on 9.2 and XP Prof. ...
    (perl.beginners)