//遍历文件夹下面所有文件及子文件夹
function read_all_dir ( $dir ){
  $result = array();
  $handle = opendir($dir);//读资源
  if ($handle){
    while (($file = readdir($handle)) !== false ){
      if ($file != '.' && $file != '..'){
        $cur_path = $dir . DIRECTORY_SEPARATOR . $file;
        if (is_dir($cur_path )){//判断是否为目录,递归读取文件
          $result['dir'][$cur_path] = read_all_dir($cur_path );
        }else{
          $result['file'][] = $cur_path;
        }
      }
    }
    closedir($handle);
  }
  return $result;
}

 

$file =read_all_dir('E:\model');

var_dump(E:\model);

//结果如下:

PHP 遍历目录下面的所有文件及子文件夹

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-14
  • 2021-10-26
  • 2021-12-06
  • 2021-09-13
  • 2022-12-23
  • 2021-09-06
  • 2021-11-13
相关资源
相似解决方案