Posted By

fackz on 08/03/09


Tagged

dir count files


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

fackz
vali29
umang_nine


count files in a given dir


 / Published in: PHP
 

count files in a given dir

  1. <?php
  2. function count_files($name) {
  3. $dirname = "galleries/$name";
  4. if(is_dir($dirname))
  5. $dir_handle = opendir($dirname);
  6. if(!$dir_handle)
  7. return false;
  8.  
  9. $files = 0;
  10.  
  11. while($file = readdir($dir_handle)) {
  12. if($file != "." and $file != "..") {
  13. if(!is_dir($dirname . "/" . $file))
  14. $files++;
  15. else
  16. $files += count_files($dirname . "/" . $file);
  17. }
  18. }
  19.  
  20. closedir($dir_handle);
  21.  
  22. return $files;
  23. }
  24. ?>

Report this snippet  

You need to login to post a comment.