php统计文件夹所有文件 及 容量大小
<?php $dirname = "test1"; //mkdir($dirname); //遍历一层目录 (统计有多少个文件 function listdir($dirname) { $ds = opendir($dirname); while($file = readdir($ds)) { $path = $dirname."/".$file; if(is_dir($file)) { echo "DIR:".$file."<br>"; if($file != "." && $file != "..") { listdir($file); } } else { echo "FILE:".$file . "<br>"; } } } //统计目录下所有文件的容量 function totdir($dirname) { //对listdir稍加修改 static $tot = 0; $ds = opendir($dirname); while($file = readdir($ds)) { $path = $dirname."/".$file; if(is_dir($file)) { //echo "DIR:".$file."<br>"; if($file != "." && $file != "..") { $tot += totdir($file); } } else { //echo "FILE:".$file . "<br>"; $tot += filesize($path); } } //返回总计 return $tot; } listdir($dirname); echo totdir($dirname)." bytes"; ?>
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。