好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

php递归遍历目录文件与文件夹 - php文件操作

php递归遍历目录文件与文件夹

他们利用了递归的方法来实例目录遍历,可以查找出无限级目录的文件与文件夹中的文件并显示,下面是实例代码:

<?php   $dir  =  'f:game' ;   function  read_dir_all( $dir ) {   $ret  =  array ( 'dirs' => array (),  'files' => array ());   if  ( $handle  = opendir( $dir )) {   while  (false !== ( $file  = readdir( $handle ))) {   if ( $file  !=  '.'  &&  $file  !==  '..' ) {   $cur_path  =  $dir  . directory_separator .  $file ;   if ( is_dir ( $cur_path )) {   $ret [ 'dirs' ][ $cur_path ] = read_dir_all( $cur_path );   }  else  {   $ret [ 'files' ][] =  $cur_path ;   }   }   }   closedir ( $handle );   }   return   $ret ;   }   $p  = read_dir_all( $dir );   echo   '<pre>' ;   var_dump( $p );   echo   '</pre>' ;   ?> 

查看更多关于php递归遍历目录文件与文件夹 - php文件操作的详细内容...

  阅读:65次