php 文件目录遍历 >递归函数

<?php


function total($dirname, &$dirnum, &$filenum){
$dir=opendir($dirname);
readdir($dir)."<br>";
readdir($dir)."<br>";
while($filename=readdir($dir)){
echo $newfile=$dirname."/".$filename;

if(is_dir($newfile)){
total($newfile, $dirnum, $filenum);
$dirnum++;
}else{
$filenum++;
}
}
closedir($dir);
}

$dirnum=0;
$filenum=0;
total("C:/AppServ/www/phpMyAdmin", $dirnum, $filenum);

echo "目录总数:".$dirnum."<br>";
echo "文件总数:".$filenum."<br>";

原文地址:https://www.cnblogs.com/fhefh/p/2108214.html