Home  >  Article  >  Backend Development  >  PHP scandir() function traverses the folder directory and all files example code

PHP scandir() function traverses the folder directory and all files example code

怪我咯
怪我咯Original
2017-07-11 09:16:491956browse

scandir() Function Returns an array of files and directories in the specified directory.

Use the php scandir function below Traverse the folder Directory and all files, the code is as follows:

<?php
$dir = "."; //当前目录
list_file($dir);
function list_file($dir){
$list = scandir($dir); // 得到该文件下的所有文件和文件夹
foreach($list as $file){//遍历
$file_location=$dir."/".$file;//生成路径
if(is_dir($file_location) && $file!="." &&$file!=".."){ //判断是不是文件夹
echo "------------------------sign in $file_location------------------";
list_file($file_location); //继续遍历
}
echo "<br/>";
}
}
?>

The above is the detailed content of PHP scandir() function traverses the folder directory and all files example code. For more information, please follow other related articles on the PHP Chinese website!

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