Irene

统计

最新评论

写一个函数,能够递归遍历一个文件夹下的所有文件和子文件夹

 

$dir = $_SERVER['DOCUMENT_ROOT'].'/tree/';

function scandir_detail($path)

{

       $files=array();

       if(is_dir($path))

       {

              $temp=scandir($path);

              foreach($temp as $file)

              {

                     if($file != '.' && $file != '..')

                     {

                            if (is_dir($path.$file)) {

                                   $files[$file]=scandir_detail($path.$file."/");

                            }else

                            {

                                   $files[]=$file;

                            }

                     }

              }

       }

       return $files;

}

function showTree($files)

{

       echo "<ul>";

       foreach($files as $key=>$file)

       {

              if(is_array($file))

              {

                     echo "<li>".$key;

                     showTree($file);

              }else

              {

                     echo "<li>".$file;

              }

       }

       echo "</ul>";

}

showTree(scandir_detail($dir));



posted on 2008-08-29 15:44 Irene 阅读(2771) 评论(0)  编辑 收藏 引用 网摘


只有注册用户登录后才能发表评论。
网站导航: