<?php//遍历当前目录下所有文件的和目录,并以树装形式显示//1.打开目录句柄,获取句柄资源//2.读取句柄资源,并显示当前和子目录下的(目录和文件名称)function getDirFile($path){ if($file_handler=opendir($path)){ while(false !== ($file=readdir($file_handler))){ if($file!="." && $file!=".."){ if(is_dir("$path/$file")){ if(substr_count("$path/$file","/")>1){ $count=str_repeat("    ",substr_count("$path/$file","/")); echo $count.$file; }else{ echo $file; } echo "<br/>"; getDirFile("$path/$file"); }else{ if(substr_count("$path/$file","/")>1){ $count=str_repeat("    ",substr_count("$path/$file","/")); echo $count.$file; }else{ echo $file; } echo "<br/>"; } } } }}$path="D:\software\wamp\www\messageboards";getDirFile($path);?> |
热门评论
-
慕斯卡64506792023-11-12 0
查看全部评论学习了,谢谢你啦! 在网上学习一些东西,代码中常常有bug,而你的,一次性运行成功,谢谢你!