Advertisement
locvfx

Files count

Dec 21st, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.58 KB | None | 0 0
  1. <?php
  2. // Count total files of a folder (included sub-folders), place it and run !
  3.  
  4. function count_files($path) {
  5.  
  6.     $file_count = 0;
  7.     $dir_handle = opendir($path);
  8.  
  9.     if (!$dir_handle) return -1;
  10.     while ($file = readdir($dir_handle)) {
  11.         if ($file == '.' || $file == '..') continue;
  12.         if (is_dir($path . $file)){      
  13.             $file_count += count_files($path . $file . DIRECTORY_SEPARATOR);
  14.         }
  15.         else {
  16.             $file_count++;
  17.         }
  18.     }
  19.  
  20.     closedir($dir_handle);
  21.     return $file_count;
  22. }
  23.  
  24. die('INODES: '.count_files(dirname(__FILE__).'/'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement