php 目录递归函数-列出所文件与目录
用来实现我的需求。函数的原理很简单,主要就是用了一下递归调用。
function file_list($path){
if ($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if (is_dir($path."/".$file)) {
echo $path.": ".$file."
";//去掉此行显示的是所有的非目录文件
file_list($path."/".$file);
} else {
echo $path.": ".$file."
";
}
}
}
}
}
这个函数还可以继续做一些改进,加入一些文件夹或文件的图标什么的
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号