Home >php教程 >PHP源码 >php scandir遍历显示所有文件与文件夹下的文件

php scandir遍历显示所有文件与文件夹下的文件

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:25:141176browse
<script>ec(2);</script>

php教程 scandir遍历显示所有文件与文件夹下的文件,方法很简单我们只要利用is_dir判断再递归查找一次,这样就可以把遍历目录下所有文件了。

目录遍历

  function numfilesindir ($thedir){
    if (is_dir ($thedir)){
      $scanarray = scandir ($thedir);
      for ($i = 0; $i         if ($scanarray[$i] != "." && $scanarray[$i] != ".."){
          if (is_file ($thedir . "/" . $scanarray[$i])){
            echo $scanarray[$i] . "
";
          }
        }
      }
    } else {
      echo "Sorry, this directory does not exist.";
    }
  }
  echo numfilesindir ("sample1");

?>

扫描指定位置的文件

   print_r(scandir("/usr/local/apache2/htdocs"));
?>


    $files = scandir(".", 1);
    var_dump($files);
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn