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!