Posted By

mscribellito on 12/09/10


Tagged

list dir files map directory scan


Versions (?)

Map a Directory


 / Published in: PHP
 

  1. function map_dir($dir = '', $recurse = true, $hidden = false) {
  2. if (empty($dir)) $dir = realpath(dirname(__FILE__));
  3. if ($link = @opendir($dir)) {
  4. $ds = DIRECTORY_SEPARATOR;
  5. $dir = rtrim($dir, $ds) . $ds;
  6. $map = array();
  7. while (false !== ($file = @readdir($link))) {
  8. if (($hidden == false && strncmp($file, '.', 1) == 0) or ($file == '.' or $file == '..')) {
  9. continue;
  10. }
  11. if ($recurse == true && @is_dir($dir . $file)) {
  12. $temp = array();
  13. $temp = map_dir($dir . $file . $ds, $recurse, $hidden);
  14. $map[$file] = $temp;
  15. }
  16. else {
  17. $map[] = $file;
  18. }
  19. }
  20. @closedir($link);
  21. return $map;
  22. }
  23. return false;
  24. }

Report this snippet  

You need to login to post a comment.