I'm trying to get the behavior like the "tree" command on linux or unix systems where the function returns a list or array of directories in its full path.
Example
~/
~/Pictures
~/Movies
~/Downloads
~/Documents
~/Documents/work
~/Documents/important
~/Documents/bills
~/Music
~/Music/80s/
etc .... etc...
foreach (new RecursiveIteratorIterator (new RecursiveDirectoryIterator ('.')) as $x)
{
echo $x->getPathname (), "\n";
}
Update #1:
If you want empty directories to be listed as well, use RecursiveIteratorIterator::CHILD_FIRST
foreach (new RecursiveIteratorIterator (new RecursiveDirectoryIterator ('.'), RecursiveIteratorIterator::CHILD_FIRST) as $x)
{
echo $x->getPathname (), "\n";
}
Checkout PHP's Recursivedirectoryiterator. It will do what you need, and it has some nice examples.
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