ITPub博客

首页 > IT职业 > IT职场 > php递归遍历目录

php递归遍历目录

IT职场 作者:danan 时间:2021-09-09 09:17:36 0 删除 编辑

其实很简单,就写了一个函数,没啥好说的直接上代码了

public function openDirectory($path)

{

    $dir = dir($path);

    while (false != ($entry = $dir->read())) {

        if ($entry != "." && $entry != "..") {

            if (is_dir($path . DIRECTORY_SEPARATOR . $entry)) {

                $this->openDirectory($path . DIRECTORY_SEPARATOR . $entry);

            } else {

                //这里做文件的操作

            }

        }

    }

}

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/2844/viewspace-2801816/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-08-16

  • 博文量
    76
  • 访问量
    414