function tree($dir,$level=1){
$fh=opendir($dir);
$dirname=readdir($fh);
$dirname=readdir($fh);
while($dirname=readdir($fh)){
echo str_repeat('-',$level).$dirname;
echo '<br>';
if(is_dir($dir. '/' .$dirname)){
tree($dir. '/' .$dirname,$level+2);
}
}
}
tree('E:\燕十八');
改善版
<?php
function tree($dir,$level=1){
$fh=opendir($dir);
while($dirname=readdir($fh)){
if($dirname == '.' || $dirname == '..'){ //用continue 跳出循环,continue 跳出当次循环,执行下次循环,跳回while 因为IF不是循环体
continue;
}
echo str_repeat('-',$level).$dirname;
echo '<br>';
if(is_dir($dir. '/' .$dirname)){
tree($dir. '/' .$dirname,$level+2);
}
}
}
tree('E:\燕十八');
?>
-每日源代码
---1119
-----01.php
-----02.php
-----03.php
-----04.php
-----05.php
-----163news.html
-----a.txt
-----b.txt
-----custom.txt
-----frame-01
-------include
---------conf.class.php
---------config.inc.php
---------db.class.php
---------init.php
-------index.php
-----modea.txt
-----modew.txt
-----今天内容.txt
-----conf类与配置文件读取.bmp
-----框架流程.bmp
---1120code
-----1120
-------frame-02
---------data
-----------log
-------------curr.log
-------------12112021463.bak
---------include
-----------config.inc.php
-----------conf.class.php
-----------db.class.php
-----------init.php
-----------log.class.php