http://www.perlmonks.org?node_id=204109


in reply to size of directory

If you're wanting to sum the sizes of all files within a directory, this should do it:

my $dir = '/path/to/dir'; my $dir_size = 0; my $file; opendir DIR, $dir or die "Unable to open $dir: $!\n"; $dir_size += -s "$dir/$file" while defined( $file = readdir DIR ); closedir DIR; print $dir_size;

This does not descend into subdirectories, though.