当前位置: 移动技术网 > IT编程>开发语言>PHP > 遍历指定目录下的所有目录和文件的php代码

遍历指定目录下的所有目录和文件的php代码

2019年04月19日  | 移动技术网IT编程  | 我要评论

孔祥熙简介,寒亭一中新校区,人体艺术网导航

复制代码 代码如下:

<?php
function listfiles($path){
$result = array();
foreach(glob($path.'\\'."*") as $item){
$result[strtolower($item)] = $item;
if(is_dir($item)){
$result += listfiles($item);
}
}
return $result;
}
$path = 'e:\\web\\dianle';
foreach(listfiles($path) as $item){
echo $item.'<br />';
}

2: scandir 读取指定目录到数组
复制代码 代码如下:

function listfiles($path){
$result = array();
foreach( scandir($path) as $item ){
if($item != '.' && $item != '..' ){
$item = $path.'\\'.$item;
$result[strtolower($item)] = $item;
if(is_dir($item)){
$result += listfiles($item);
}
}
}
return $result;
}
$path = 'e:\\web\\dianle';
foreach(listfiles($path) as $item){
echo $item.'<br />';
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网