I am trying to use PHP's RecursiveDirectoryIterator to list a set of directories. The issue I am having is that it seems to be skipping any empty directory it hits. Any ideas how to make it list empty directories?
Here is a clip of the code I am using:
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($root));
$result = array();
$prefix_length = strlen($root) + 1;
foreach($iterator as $file)
{
if($file->isDir())
{
$result[] = dirname(substr($file->__toString(), $prefix_length));
}
}
Try:
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($root), RecursiveIteratorIterator::SELF_FIRST
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With