$dir = realpath($dir);
// some flags to filter . and .. and follow symlinks
$flags = FilesystemIterator::SKIP_DOTS | FilesystemIterator::FOLLOW_SYMLINKS;
// create a simple recursive directory iterator
$iterator = new RecursiveDirectoryIterator($dir, $flags);
// make it a truly recursive iterator
$iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
// iterate over it
foreach ($iterator as $file)
{
// do something with $file (a SplFileInfo instance)
/* @var $file SplFileInfo */
if ($file->isFile()) {
} elseif ($file->isDir) {
}
}
Title:
php directory iterator recursive
Description:
$dir = realpath($dir); // some flags to filter . and .. and follow symlinks $flags = FilesystemIterator::SKIP_DOTS | FilesystemIterator::F...
...
Rating:
4