• PHP 批量获取指定目录下的文件列表(递归,穿透所有子目录)


    //调用
    $dir = '/Users/xxx/www';
    $exceptFolders = array('view','test');
    $exceptFiles = array('BaseController.php','LogController.php');
    $files = getFilesFromFolder($dir,$exceptFolders,$exceptFiles);
    print_r($files);
    
    /**
     * 批量获取指定目录下的文件列表
     * @param string $folder 指定的目录
     * @param array() $exceptFolders 排除的目录
     * @param array() $exceptFiles 排除的文件
     */
    function getFilesFromFolder($dir,$exceptFolders,$exceptFiles){
        foreach ($exceptFolders as $k1=>$v1){
            $except_fo[] = $dir.'/'.$v1;
        }
        foreach ($exceptFiles as $k2=>$v2){
            $except_fi[] = $dir.'/'.$v2;
        }
        
        global $file_list;
         if(is_dir($dir)&&file_exists($dir)){
             $ob=scandir($dir);
             foreach($ob as $file){
                  if($file=="."||$file==".."){
                       continue;
                  }
                  $file=$dir."/".$file;
                  if(is_file($file)){
                          if(pathinfo($file)['extension'] == 'php' && !in_array($file, $except_fi)){
                              $file_list[] = $file;
                          }
                  }elseif(is_dir($file)){
                          if(!in_array($file, $except_fo)){
                              getFilesFromFolder($file,$exceptFolders,$exceptFiles);
                          }
                  }
             }
         } 
    
         return $file_list;
    }
  • 相关阅读:
    JVM(7) Java内存模型与线程
    JVM(6) 字节码执行引擎
    JVM(5) 类加载机制
    JVM(4) 类文件结构
    JVM(3) 垃圾收集器与内存分配策略
    python的with
    python http server handle json
    c++文件读写
    python字符串处理
    python decorator
  • 原文地址:https://www.cnblogs.com/rxbook/p/6772643.html
Copyright © 2020-2023  润新知