我想用php代码动态的将C:/WINDOWS下面的所有文件夹和子文件夹用tree的形式在页面显示,该怎么做啊?最好能发全部的代码,谢谢!

解决方案 »

  1.   


    function   listDirTree(   $dirName   =   null   )    
      {  
      if(   empty(   $dirName   )   )  
      exit(   "IBFileSystem:   directory   is   empty."   );  
       
      if(   is_dir(   $dirName   )   )  
      {  
      if(   $dh   =   opendir(   $dirName   )   )  
      {  
      $tree   =   array();  
      while(   (   $file   =   readdir(   $dh   )   )   !==   false   )  
      {  
      if(   $file   !=   "."   &&   $file   !=   ".."   )  
      {  
      $filePath   =   $dirName   .   "/"   .   $file;  
       
      if(   is_dir(   $filePath   )   ) //为目录,递归  
      {  
      $tree[$file]   =   listDirTree(   $filePath   );  
      }  
      else //为文件,添加到当前数组  
      {  
      $tree[]   =   $file;  
      }  
      }  
      }  
      closedir(   $dh   );  
       
      }  
      else  
      {  
      exit(   "IBFileSystem:   can   not   open   directory   $dirName.");  
      }  
       
      //返回当前的$tree  
      return   $tree;  
      }  
       
      else  
      {  
      exit(   "IBFileSystem:   $dirName   is   not   a   directory.");  
      }  
      }print_r(listDirTree("d:/tools"));返回的数组就是结构
      

  2.   

    http://www.zzxj.net/blog/fxs_2008/archive/2009/02/12/23.html
      

  3.   

    function readfolder($path) 

    if ($handle=@opendir($path)) 
        { 
    //echo "a";
    while (false!==($file=readdir($handle))) 

    if ($file<>"." AND $file<>"..") 

    if (is_file($path.'\\'.$file)) 

    //@unlink($path.'/'.$file); 
    //echo "<br>".$path.'/'.$file; 
    //$fileArray[]
     echo $path"."\\".$file;  

    if (is_dir($path.'\\'.$file)) 

       $filelist.=readfolder($path.'\\'.$file); 
    }
    }
    }
    }
    return $filelist;
    }
      

  4.   

    如果你的php是5.0以上的话,<?php$dir = "D:\\cc";$handle = new RecursiveDirectoryIterator(new DirectoryIterator($dir));foreach($handle as $vv)
    {
    echo $handle->getFileName() . "<br>";
    }?>