Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub calcDiskUsage {
- my $path = shift;
- my $count = 0;
- return 0 if (!-d $path);
- my $dh = undef;
- if (opendir($dh,$path)) {
- while (my $direntry = readdir($dh)) {
- next if ($direntry eq "." || $direntry eq "..");
- if (-d $path."/".$direntry) {
- $count += calcDiskUsage($path."/".$direntry);
- } else {
- if (defined((stat($path."/".$direntry))[7]) && defined($path) && defined($direntry)) {
- $count += (stat($path."/".$direntry))[12];
- }
- }
- }
- closedir($dh);
- } else {
- &log("Unable to open dir $path: $!");
- }
- return $count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement