Home > Archive > PERL Beginners > August 2005 > Directory Size
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| 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
| |
|
|
> -----Original Message-----
> From: Nick [mailto:lists@mogmail.net]
> 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 );
| |
|
| On Sun, 28 Aug 2005 18:25:43 +0100
Nick <lists@mogmail.net> wrote:
> 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.
If you search Google on 'perl directory size du' you will get lots of answers
--
Owen
| |
| John W. Krahn 2005-08-28, 9:55 pm |
| Nick wrote:
> Hi All,
Hello,
> 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".
http://ppt.perl.org/commands/du/index.html
John
--
use Perl;
program
fulfillment
|
|
|
|
|