Home  >  Article  >  Backend Development  >  用PHP实现递归循环每一个目录_PHP

用PHP实现递归循环每一个目录_PHP

WBOY
WBOYOriginal
2016-06-01 12:18:04795browse

函数的原理很简单,主要就是用了一下递归调用。
复制代码 代码如下:
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