Posted By

ginoplusio on 12/15/09


Tagged

dir recursive directory opendir


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

xmartyxcorex


Dir size recursive php function


 / Published in: PHP
 

URL: http://www.barattalo.it/2010/02/01/calculate-dir-size-recursively/

Calculate dir size recursive, follow the link above because the version above is better.

  1. function dirsize($dir,$buf=2) {
  2. static $buffer;
  3. if(isset($buffer[$dir])) return $buffer[$dir];
  4. if(is_file($dir)) return filesize($dir);
  5. if($dh=opendir($dir)) {
  6. $size=0;
  7. while(($file=readdir($dh))!==false) {
  8. if($file=='.' || $file=='..') continue;
  9. $size+=dirsize($dir.'/'.$file,$buf-1);
  10. }
  11. closedir($dh);
  12. if($buf>0) $buffer[$dir]=$size;
  13. return $size;
  14. }
  15. return false;
  16. }

Report this snippet  

You need to login to post a comment.