RecursiveIteratorIterator

RecursiveIteratorIterator

我发现在PHP中,我可以用下面的代码获取文件夹的所有子目录。$address = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS),RecursiveIteratorIterator::SELF_FIRST,RecursiveIteratorIterator::CATCH_GET_CHILD // Ignore "Permission denied");把它放在$地址里。我如何添加一个标准,如果子目录里面有“TMP”文件夹,然后把它放在$地址? 最佳答案 您可以创建自己的 cc >$dir = new RecursiveDirectoryIterator(__DIR__, RecursiveDirectoryIterator::SKIP_DOTS);$address = new RecursiveIteratorIterator(new TmpRecursiveFilterIterator($dir), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD);foreach($address as $dir) { echo $dir,PHP_EOL;}使用的类class TmpRecursiveFilterIterator extends RecursiveFilterIterator { public function accept() { $file = $this->current(); if ($file->isDir()) { return is_dir("$file/tmp"); } return false; }}
10-08 08:49