The number of specified extension files in PHP recursive statistics directory
[code]/**
* specified extension name file number
* Number
*/
function get_file_count ($dir, $ext) {
$count = 0;
$dp = opendir ($dir); "/ '. $curFile)) {
/ / / / / if the current file is a directory, the statistics function is called recursively, and the count of the number of files is accumulated to the result of the current directory statistics.
$count = get_file_count ($dir. '/'. $curFile, $ext);
} else {
/ / / check the extension of the current file, if it meets the requirement, accumulative counter.
if (preg_match (.Quot; /.{$ext}$/i.quot; $curFile)) {
$count;
}
}
}
>; / / / / / Test Statistics C E file. There are too many files. [/code]
we can make a small change to let him count only the files under the root directory of the C disk, excluding the directory
[code]/**
*
* @param string $dir statistical directory path
* @param extensions. $ext) {
$count = 0;
$dp = opendir ($dir);
while (false = = $curFile = readdir). $count;
}
}
}
return $count;
}
echo get_file_count (''); / / / / / / Test Statistics C root directory of how many files, excluding directory