<?
php
function traverseDir(
$path = "."
) {
$currentDir =
opendir (
$path );
// opendir()返回一个目录句柄,失败返回false
while ( (
$file =
readdir (
$currentDir )) !==
false ) {
// readdir()打开目录句柄中的一个条目
$subDir =
$path . DIRECTORY_SEPARATOR .
$file;
// 构建子目录路径
if (
$file == "." ||
$file == ".."
) {
continue;
} elseif (
is_dir (
$subDir )) {
// 如果是目录直接递归
echo "Directory" .
$file . ":<br/>"
;
traverseDir ( $subDir );
} else {
echo "File in the dir
$path :
$file <br/>";
// 如果是文件直接输出
}
}
}
traverseDir ( "test"
);
?>
转载于:https://www.cnblogs.com/eterwei/p/3778062.html
相关资源:PHP遍历目录及子目录所有文件并下载
转载请注明原文地址: https://win8.8miu.com/read-25811.html