递归查找指定类型的文件
1 2 3 4 5 6 |
$it1 = new RecursiveDirectoryIterator($path); $files = new RecursiveIteratorIterator($it1); $regexIterator = new RegexIterator($files, '/\.(css|js|html|php|tpl)$/'); foreach ($regexIterator as $fileInfo) { } |
弄个函数
1 2 3 4 5 6 7 8 9 |
protected function getFiles($path, $pattern, $recursion = false){ if($recursion){ $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); } else { $it = new FilesystemIterator($path); } return new RegexIterator($it, $pattern); } |