Copy code The code is as follows:
$dirname = "test1";
//mkdir( $dirname);
//Traverse one level of directories
function listdir($dirname) {
$ds = opendir($dirname);
while($file = readdir($ds )) {
$path = $dirname.'/'.$file;
if(is_dir($file)) {
echo "DIR:".$file."
";
if($file != "." && $file != "..") {
listdir($file);
}
}
else {
echo " FILE:".$file . "
";
}
}
}
function totdir($dirname) { //Slightly modify listdir
static $tot = 0;
$ds = opendir($dirname);
while($file = readdir($ds)) {
$path = $dirname.'/'.$file;
if(is_dir($file)) {
//echo "DIR:".$file."
";
if($file != "." && $file != ". .") {
$tot += totdir($file);
}
}
else {
//echo "FILE:".$file . "
" ;
$tot += filesize($path);
}
}
//Return total
return $tot;
}
listdir ($dirname);
echo totdir($dirname)." bytes";
?>
http://www.bkjia.com/PHPjc/781034.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/781034.htmlTechArticleCopy the code as follows: ?php $dirname = "test1"; //mkdir($dirname); // Traverse one level of directories function listdir($dirname) { $ds = opendir($dirname); while($file = readdir($ds)) { $pat...