当前位置:Gxlcms > PHP教程 > php遍历子文件

php遍历子文件

时间:2021-07-01 10:21:17 帮助过:19人阅读

"; }?>
]

要是遍历d盘的时候,由于文件太多,会卡在哪里很久
有没有什么优化的方法


回复讨论(解决方案)

减少遍历的范围是唯一优化的方法
使用 glob 不递归或目录迭代器可使速度提高,但也有限

$p = './';$res = glob("$p/*");for($i=0; $i  
$path = '.';$ite = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path) );$deep = 0;foreach ($ite as $cur) {  $fn = $cur->getBasename();  if($fn == '.' || $fn == '..') continue;  $res[] = $fn;  if(($d=$ite->getDepth()) == $deep);  echo "$d $fn 
";}

人气教程排行