Posted By

iloveitaly on 07/07/09


Tagged

list array files directory listdir


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ashloren
vali29


Get List of Files in Directory


 / Published in: PHP
 

Like python's os.listdir

  1. function listdir($directory, &$list = array(), $base = '') {
  2. $iterator = new DirectoryIterator($directory);
  3.  
  4. foreach($iterator as $file) {
  5. $name = $file->getFilename();
  6.  
  7. if($name[0] != '.') {
  8. if($file->isDir()) {
  9. listdir($directory.'/'.$name, &$list, $name.'/');
  10. } else {
  11. $list[] = $base.$name;
  12. }
  13. }
  14. }
  15.  
  16. return $list;
  17. }

Report this snippet  

You need to login to post a comment.