如何使用scandir函数获取指定目录下的所有文件及文件夹列表?
- 内容介绍
- 文章标签
- 相关推荐
本文共计103个文字,预计阅读时间需要1分钟。
php
function list_files($dir) { $list=scandir($dir); foreach ($list as $file) { $file_location=$dir . / . $file; if (is_dir($file_location)) { // 处理文件夹 } else { // 处理文件 } }}?>
<?php $dir = "."; //当前目录 list_file($dir); function list_file($dir){ $list = scandir($dir); // scandir得到该文件下的所有文件和文件夹 foreach($list as $file){//遍历 $file_location=$dir."/".$file;//生成路径 if(is_dir($file_location) && $file!="." &&$file!=".."){ //判断是不是文件夹 echo "------------------------sign in $file_location------------------<BR>"; list_file($file_location); //继续遍历 } echo $dir."/".$file."<br/>"; } } ?>
本文共计103个文字,预计阅读时间需要1分钟。
php
function list_files($dir) { $list=scandir($dir); foreach ($list as $file) { $file_location=$dir . / . $file; if (is_dir($file_location)) { // 处理文件夹 } else { // 处理文件 } }}?>
<?php $dir = "."; //当前目录 list_file($dir); function list_file($dir){ $list = scandir($dir); // scandir得到该文件下的所有文件和文件夹 foreach($list as $file){//遍历 $file_location=$dir."/".$file;//生成路径 if(is_dir($file_location) && $file!="." &&$file!=".."){ //判断是不是文件夹 echo "------------------------sign in $file_location------------------<BR>"; list_file($file_location); //继续遍历 } echo $dir."/".$file."<br/>"; } } ?>

