get directory paths recursively using SPL ... was Re: [PHP] Am I supposed to be using SPL?

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

 



Jochem Maas wrote:
also take a look here:
http://www.wiki.cc/php/RecursiveDirectoryIterator

yes it's meant to be used, yes you can use it in production BUT your
a little on the bleeding edge (not very many people using it full on) AND
the whole of SPL is still a little in flex (as is php5->php6 in general) so
that you may be forced, occasionally, to adapt your code to changes (e.g.
constants that were formally used in SPL are now class constants.)

Wow, this is some magical stuff.  Here is my function in case it's of use:

   //----------------------------------------------------------------------
   /**
    * Magical SPL code to recursively list files in a directory
    */
   public static function get_paths_recursive($start_path) {
       $paths = array();
       $rdi = new RecursiveDirectoryIterator($start_path);
       foreach (new RecursiveIteratorIterator($rdi) as $path) {
           array_push($paths, (string) $path);
       }
       return $paths;
   }

   //----------------------------------------------------------------------

This iterates over objects like arrays, casts objects as strings, and iterates iterators. All sorts of fun and joy enough to make your head spin. Seems to
work, though ;-)

Thanks for the wiki doc link, Jochem.

Dante

--
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