----- Original Message -----
From: "Alan Haggai Alavi" <alanhag...@alanhaggai.org>
To: <beginners@perl.org>; "Mike Blezien" <mick...@frontiernet.net>
Sent: Wednesday, October 27, 2010 8:13 PM
Subject: Re: Directory Size
On Thursday 28 Oct 2010 06:30:01 Mike Blezien wrote:
Hello,
I've been out of the programming game for a while and recently got back
into some small programming projects. Just need to figure out if there is
a Perl function to determine the total size of a folder and files? Meaning
once we open/read a directory is to calculate the total, in MB's, the size
of the files in a particular directory folder.
Thanks,
Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Hi Mike,
You could make use of File::Find's find function along with stat.
=pod Example
use strict;
use warnings;
use File::Find;
my $size;
my $directory = '/path/to/some/directory';
sub determine_size {
if ( -f $File::Find::name ) {
$size += ( stat $File::Find::name )[7];
}
}
find( \&determine_size, $directory );
$size /= 1024 * 1024;
print "Total size: $size MB\n";
=cut
Relevant documents to read:
`perldoc File::Find` - http://perldoc.perl.org/File/Find.html
`perldoc -f stat` - http://perldoc.perl.org/functions/stat.html
Regards,
Alan Haggai Alavi.
Thank you Alan I think this was exactly what I was looking for, now I recall how
it's done again. :)
MIke
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/