Home >php教程 >PHP源码 >遍历某文件夹下的所有文件和文件夹 方法五(请无视)

遍历某文件夹下的所有文件和文件夹 方法五(请无视)

PHP中文网
PHP中文网Original
2016-05-25 17:15:441136browse

php代码

function list_dir($dirpath){
 	if($dirpath[strlen($dirpath)-1]!="\\"){$dirpath.="\\";}
 	static $result_array=array();
 	if(is_dir($dirpath)){
 		$handle=opendir($dirpath);
 		while($file=readdir($handle)){
 			if($file=="."||$file==".."){continue;}
 			if(is_dir($dirpath.$file)){
 				list_dir($dirpath.$file."\\");
 			}else{
 				array_push($result_array,$dirpath.$file);
 			}
 		}
 		closedir($handle);
 	}
 	return $result_array;
 }

 $array=list_dir("D:\www");
 foreach($array as $value){
 	echo $value;
 	echo "
";
 }

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
Previous article:第二种分页类Next article:php防止页面刷新代码