Home > php教程 > php手册 > php递归法读取目录及文件的方法,

php递归法读取目录及文件的方法,

WBOY
Release: 2016-06-13 09:16:06
Original
909 people have browsed it

php递归法读取目录及文件的方法,

本文实例讲述了php递归法读取目录及文件的方法。分享给大家供大家参考。具体如下:

这里实例分析php递归法读取目录及文件的方法,代码中包含较为详尽的注释,如下所示:

<&#63;php
function showdir($path){
 $dh = opendir($path);//打开目录
 while(($d = readdir($dh)) != false){
 //逐个文件读取,添加!=false条件,是为避免有文件或目录的名称为0
 if($d=='.' || $d == '..'){//判断是否为.或..,默认都会有
 continue;
 }
 echo $d."<br />";
 if(is_dir($path.'/'.$d)){//如果为目录
 showdir($path.'/'.$d);//继续读取该目录下的目录或文件
 }
 }
}

$path = './';//当前目录
showdir($path);
&#63;>
Copy after login

希望本文所述对大家的php程序设计有所帮助。

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template