Home >php教程 >PHP源码 >php 目录递归函数-列出所文件与目录

php 目录递归函数-列出所文件与目录

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:29:231047browse
<script>ec(2);</script>

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."
";
}
}
}
}
}

这个函数还可以继续做一些改进,加入一些文件夹或文件的图标什么的

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn