<BR><?php <BR>$dirname = "test1"; <BR>//mkdir($dirname); <br><br>//遍历一层目录 <BR>function listdir($dirname) { <BR>$ds = opendir($dirname); <BR>while($file = readdir($ds)) { <BR>$path = $dirname.'/'.$file; <BR>if(is_dir($file)) { <BR>echo "DIR:".$file."<br>"; <BR>if($file != "." && $file != "..") { <BR>listdir($file); <BR>} <BR>} <BR>else { <BR>echo "FILE:".$file . "<br>"; <BR>} <BR>} <BR>} <br><br>function totdir($dirname) { //对listdir稍加修改 <BR>static $tot = 0; <BR>$ds = opendir($dirname); <BR>while($file = readdir($ds)) { <BR>$path = $dirname.'/'.$file; <BR>if(is_dir($file)) { <BR>//echo "DIR:".$file."<br>"; <BR>if($file != "." && $file != "..") { <BR>$tot += totdir($file); <BR>} <BR>} <BR>else { <BR>//echo "FILE:".$file . "<br>"; <BR>$tot += filesize(<strong style="color:transparent">本文来源gao@daima#com搞(%代@#码@网&</strong><strong>搞gaodaima代码</strong>$path); <BR>} <BR>} <br><br>//返回总计 <BR>return $tot; <BR>} <br><br>listdir($dirname); <br><br>echo totdir($dirname)." bytes"; <br><br>?> <BR>