Get List of Files in Directory


/ Published in: PHP
Save to your folder(s)

Like python's os.listdir


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.