zoukankan      html  css  js  c++  java
  • 获取一个目录下的所有文件

    知道一个目录的路径,使用递归获取该目录下的所有文件:

    function rDir($filepath)
    {
      $result = array();//获取的结果保存在这个数组中
      if(is_dir($filepath))
      {
        $re = opendir($filepath);
        while (($file=readdir($re)) != false)
        {
          if ($file != '.' && $file != '..')
          {
            $curpath = $filepath.'/'.$file;
            if (is_dir($curpath))
            {
              $func = __FUNCTION__;
              $res = $func($curpath);
              $result[$file]=$res;
            }

            else
            {
              $result[]=$file;
            }
          }
        }
        closedir($re);
        return $result;
      }
      else if(is_file($filepath))
      {
        return '这个是文件,不是目录';
      }
      else
      {
        return '这是什么东西?';
      }
    }

  • 相关阅读:
    uva 11728 Alternate Task
    uvalive 5009 Error Curves
    uva 10341 Solve It
    uva 10870 Recurrences
    uva 11021 Tribbles
    17年9月6日
    React实践相关
    React:Refs and DOM
    React:propTypes
    React:JSX 深入
  • 原文地址:https://www.cnblogs.com/walksnow/p/6011973.html
Copyright © 2011-2022 走看看