php遍历文件夹php
使用获取文循环遍历得到一个目录下的所有文件。
function get_Path_ls($dir)
{
$cmdls="/bin/ls '".$dir."'";
$retls=shell_exec($cmdls." 2>&1");
$arrls=explode("\n",$retls);
$arrlsf=array();
foreach ($arrls as $kl => $vl)
{
//为空,和. .. 忽略
if (($vl=='') || ($vl=='.') || ($vl=='..'))
{
continue;
}
$vl=trim($vl);
if(strpos($vl,"'") >0)
{
$newfindfile=str_replace("'","",$vl);
$newpathfile=$dir."/".$newfindfile;
rename($dir."/".$vl,$newpathfile);
$arrlsf[]=$newfindfile;
}
else
{
$arrlsf[]=$vl;
}
}
return $arrlsf;
通过这个get_Path_ls函数只要传入一个要遍历的地址,就能返回这个文件夹下的所有文件。
我要评论