PHP生成器递归遍历目录
2023-10-30 14:17:17 Author: www.yanglong.pro(查看原文) 阅读量:14 收藏

    private function fullScanDir($dir): \Generator
    {
        $list = scandir($dir);
        foreach ($list as $filename) {
            if ($filename === '.' || $filename === '..') continue;
            if ($filename === '.git') continue;
            $aDir = sprintf("%s/%s", $dir, $filename);
            if (is_dir($aDir)) {
                foreach ($this->fullScanDir($aDir) as $_filename) {
                    yield $_filename;
                }
            } else {
                yield $aDir;
            }
        }
    }

文章来源: https://www.yanglong.pro/php%e7%94%9f%e6%88%90%e5%99%a8%e9%80%92%e5%bd%92%e9%81%8d%e5%8e%86%e7%9b%ae%e5%bd%95/
如有侵权请联系:admin#unsafe.sh