PHP recursive implementation traversal with Dir return object
Read ()) {//directory with hidden file '. ') and '. ' When traversing requires attention to if ((Is_dir ("$dir/$file") && ($file! = ".") && ($file! = "...")) {echo $file. '
'; Loop ("$dir/$file"); Recursive loop}else{if ($file! = ":" && $file! = ".") {echo $file. "
"; }}}} loop (DirName (__file__)); DirName Remove file name return directory name//non-recursive processing traverse directory//idea: First create an array, because the first pass is a directory name minus the file name (such as c://wamp/www/php)//For the Foreach Loop so the first time to put c://wamp/ All the files under www/php are put into the array//only enough while cycle the last one of each output array, when the file is a directory, the Foreach Loop//Know the last value when the Count ($list) value is 0 exit the loop function ScanAll ($dir) {$list = array (); $list [] = $dir; while (count ($list) > 0) {//Var_dump ($list); The last element of the popup array $file = Array_pop ($list); Handles the current file echo $file.
"; If it is a directory if (Is_dir ($file)) {$children = Scandir ($file); Var_dump ($children); foreach ($children as $child) {if ($child!== '. ' && $child!== ') {$list [] = $file. ' /'. $child; }}}}}scanall (DirName (__file__));