Posted By

DrewDouglass on 07/12/09


Tagged

php


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

vali29
GandalfGrey
AzizLight
qubestream
SFLWebDev


Recursive Directory Listing (Show full directory structure)


 / Published in: PHP
 

URL: http://us2.php.net/manual/en/class.recursivedirectoryiterator.php

Takes advantage of the SPL. Much easier and maintainable than the previous revisions. Haven't done any benchmarks yet but I imagine it is much faster. "If you want to omit directories, remove the RecursiveIteratorIterator::SELF_FIRST part."

  1. <?php
  2. $path = realpath('/etc');
  3.  
  4. $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
  5. foreach($objects as $name => $object){
  6. echo "$name\n";
  7. }
  8. ?>

Report this snippet  

You need to login to post a comment.