zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    记录按钮点击次数,点击三次之后跳转页面
    HTML拖放
    .Net实现发送邮件功能
    HTTP 400 错误
    方法(参数的传递)
    方法
    c# 属性 (get、set)
    Python和C++交互
    从Windows远程Ubuntu
    Eclipse+Tomcat WEB开发配置
  • 原文地址:https://www.cnblogs.com/rxbook/p/6772643.html
Copyright © 2011-2022 走看看