1<?PHP2 3 Header("content-type:text/html; Charset=utf8 ");4 //recursively view catalog files5 6 $pathname= "d:/qq";7 //call a recursive function8 $res= Digui ($pathname);9 Var_dump($res);Ten one functionDigui ($pathname,$deep=0){ a //Store all traversed file contents - Static $file _list=Array(); - the //Open Directory handle - $handle=Opendir($pathname); - while(false!== ($filename=Readdir($handle))) {//false!== prevent the directory file name 0 from appearing - //filter The Point folder of the Re-folders + if($filename= = '. ' | |$filename= = ' ... ') { - Continue; + } a at - //Output current directory information - //echo str_repeat (" ", $filename). " <br> "; - - //declare array variables to store directory information traversed at once - $file=Array(); in $file[' filename '] =$filename; - $file[' Deep '] =$deep; to + //Store The above information in a static array - $file _list[] =$file; the * if(Is_dir($pathname.‘ /‘.$filename)) { $ //variable FunctionsPanax Notoginseng $current _func=__function__;//get the current function name - $current _func($pathname.‘ /‘.$filename,$deep+1); the } + } a //closedir-closing a directory handle the Closedir($handle); + - return $file _list; $}
Directory Traversal of PHP