<br><?php <BR>/************************ <BR>A simple directory recursive function<BR>The first implementation method: use dir to return the object<BR>***** ********************/ <BR>function tree($directory) <BR>{ <BR>$mydir=dir($directory); <BR>echo "<ul>n"; <br>while($file=$mydir->read()){ <br>if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")) <br>{echo "<li><font color="#ff00cc"><b>$file</b></font></li>n"; <br>tree("$directory/$file"); <br>} <br>else <br>echo "<li>$file</li>n"; <br>} <br>echo "</ul>n"; <br>$mydir->close(); <br>} <br>//开始运行 <br>echo "<h2>目录为粉红色</h2><br>n"; <br>tree("F:/"); <br>/*********************** <br>The second implementation method: use the readdir() function <br>************ **************/ <br>function listDir($dir){ <br>if(is_dir($dir)){ <br>if ($dh = opendir($dir)) { <br>while (($file= readdir($dh)) !== false){ <br>if((is_dir($dir."/".$file)) && $file!="." && $file!=".."){ <br>echo "<b><font color='red'>文件名:</font></b>",$file,"<br><hr>"; <br>listDir($dir."/".$file."/"); <br>}else{ <br>if($file!="." && $file!=".."){ <br>echo $file."<br>"; <br>} <br>} <br>} <br>closedir($dh); <br>} <br>} <br>} <br>//开始运行 <br>listDir(E:/常用软件备份/); <br>?> <br>