源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-01-16 13:52 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:遍历指定目录下的所有目录和文件的php代码
[u]复制代码[/u] 代码如下:
<?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 读取指定目录到数组
[u]复制代码[/u] 代码如下:
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 />'; }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部