I want to use the RecursiveDirectoryIterator to list files and directories recursively. Below is my code.
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(".", RecursiveDirectoryIterator::SKIP_DOTS));
foreach ($rii as $file){
if ($file->isDir()) {
echo "D ".$file->getPathName();
} else {
echo "F ".$file->getPathName();
}
echo "<br>\n";
}
The problem is that it does not return directories at all. Only files are listed. When I omit the SKIP_DOTS flag, I do get directories but in the form of dir/.
and dir/..
which is obviously not what I want.
Now I could of course strip the trailing dots myself, but I wonder if there's a better builtin method I'm not aware of?