Recursive Directory Iterator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is my first time trying out the SPL iterators.
Im trying to figure out how to recursively move over a directory.
With the code that I've provided
1. Is this the correct way to use it? Im using recursive functions to go deep.
I thought, that the class would do that for me somehow...
2. As it stands, it doesn't report the correct directory structure.
For example, if I had a directory in the root with another directory under it,
the second directory doesnt get echoed.


Thanks

------
dirr('.');

function dirr($dir)
{
   $dir = new RecursiveDirectoryIterator($dir);

   foreach($dir as $foo)
   {
       echo $foo->getPathname() . '<br />';

       if ($foo->hasChildren())
       {
           $bar = $foo->getChildren();

           foreach($bar as $foo2)
           {
                if ($foo2->hasChildren())
                {
                    dirr($foo2->getPathname());
                }
                else
                {
                    echo $foo2->getPathName() . '<br />';
                }
           }
       }
   }
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux