The number of specified extension files in PHP recursive statistics directory

time:17-03-20 forum:PHP tools and code
  https://www.latrell.me/post-45.html

[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

prev:The timed display and hidden layer next:The function of the size of the PHP stat...
post comment
Notice



approved   In the mountains, after 80 years hai...   The General Administration of food a...   She turned the "abnormal" into a win...   Primary school is now "adult corrupt...   
rand   Capture the HTML content of the web ...   Three MYSQL client management tools   She turned the "abnormal" into a win...   Primary school is now "adult corrupt...   
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com