Topic. I'm trying to get the size of a directory without using the Find module and without using the du command. Here's how I'm currently approaching it but it doesn't seem like it's returning the correct size. It's returning 418836 bytes but when I run du -s the directory size is 141508.
my $size = dir_size('wp-content');
sub dir_size {
my $dir = shift;
my $size = 0;
opendir(DIR,"$dir");
foreach my $node (grep(!/^\.\.?/,readdir())) {
stat($node);
if(-f $node) {
$size += -s $node;
} elsif(-d $node) {
$size += dir_size("$dir/$node");
}
}
closedir(DIR);
return $size;
}
hoping someone can point out what im doing wrong.