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

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

怪我咯
Release: 2023-03-13 12:44:01
Original
2015 people have browsed it

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/>";
}
}
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template