php遍历文件夹php

/ / 2018-01-23   阅读:2492
使用获取文循环遍历得到一个目录下的所有文件。 function get_Path_ls($dir) {      $cmdls="/bin/ls '".$dir."'";      $retls=shell_exec($cmdls." 2>&1"); &n...

使用获取文循环遍历得到一个目录下的所有文件。

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函数只要传入一个要遍历的地址,就能返回这个文件夹下的所有文件。

我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈