php recursively counts the number of folders and files
<?php header('Content-type:text/html;charset=utf8'); /** * countDir() 递归统计文件夹数量和文件数量 * @param $dirname 文件夹名 * @return $arr 文件夹数量和文件数量 */ function countDir($dirname){ global $dirnum,$filenum; if(!file_exists($dirname)){ return false; } $dir = opendir($dirname); readdir($dir); readdir($dir); while($filename = readdir($dir)){ $newfile = $dirname.'/'.$filename; if(is_dir($newfile)){ countDir($newfile); $dirnum++; }else{ $filenum++; } } return array($dirnum,$filenum); } $a = countDir('C:\wamp\www\erhaodian'); var_dump($a); ?>
Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the PHP recursive statistics of the number of folders and files, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.