Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.87 KB | None | 0 0
  1. sub calcDiskUsage {
  2.         my $path = shift;
  3.         my $count = 0;
  4.  
  5.         return 0 if (!-d $path);
  6.  
  7.         my $dh = undef;
  8.         if (opendir($dh,$path)) {
  9.                 while (my $direntry = readdir($dh)) {
  10.                         next if ($direntry eq "." || $direntry eq "..");
  11.                         if (-d $path."/".$direntry) {
  12.                                 $count += calcDiskUsage($path."/".$direntry);
  13.                         } else {
  14.                                 if (defined((stat($path."/".$direntry))[7]) && defined($path) && defined($direntry)) {
  15.                                         $count += (stat($path."/".$direntry))[12];
  16.                                 }
  17.                         }
  18.                 }
  19.                 closedir($dh);
  20.         } else {
  21.                 &log("Unable to open dir $path: $!");
  22.         }
  23.         return $count;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement