I have this PHP Code:
$rootpath = \'../admin/\';
$inner = new RecursiveDirectoryIterator($rootpath);
$fileinfos = new RecursiveIteratorIterator($inner);
for
In essence, my answer is not much different from Thomas' answer. However, he does not get a few things correct:
RecursiveCallbackFilterIterator
require you to return true
to recurse into subdirectories..
and ..
directories inside each sub-directoryin_array
check doesn't quite do what he expectsSo, I wrote this answer instead. This will work correctly, assuming I understand what you want:
Edit: He has since fixed 2 of those three issues; the third may not be an issue because of the way he wrote his conditional check but I am not quite sure.
hasChildren() && !in_array($file->getFilename(), $exclude)) {
return true;
}
return $file->isFile();
};
$innerIterator = new RecursiveDirectoryIterator(
$directory,
RecursiveDirectoryIterator::SKIP_DOTS
);
$iterator = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator($innerIterator, $filter)
);
foreach ($iterator as $pathname => $fileInfo) {
// do your insertion here
}