PHP遍历目录下的所有文件

WBOY
Release: 2016-06-13 12:17:51
Original
939 people have browsed it

PHP遍历目录下的全部文件

代码如下:

function listDir($dir){	if(is_dir($dir)){		if ($dh = opendir($dir)){			while (($file = readdir($dh)) !== false){				if((is_dir($dir."/".$file)) && $file!="." && $file!=".."){					echo "<b><font color="'red'">文件名:</font></b>",$file,"<br><hr>";					listDir($dir."/".$file."/");				}else{					if($file!="." && $file!=".."){						echo $file."<br>";					}				}			}			closedir($dh);		}	}}
Copy after login

打印结果如下:

文件名:10


文件名:5

2012-12-11.xls
2015-02-01.z
2015-03-11.txt
2015-04-01.rar
文件名:8

可以根据需求改动代码。


Related labels:
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!