php traverses all files and folders under a certain folder
- function list_dir($dirpath){
- if($dirpath[strlen($dirpath)-1]!="\"){$dirpath.= "\";}
- static $result_array=array();
- if(is_dir($dirpath)){
- $handle=opendir($dirpath);
- while($file=readdir($handle)){
- if( $file=="."||$file==".."){continue;}
- if(is_dir($dirpath.$file)){
- list_dir($dirpath.$file."\");
- }else{
- array_push($result_array,$dirpath.$file);
- }
- }
- closedir($handle);
- }
- return $result_array;
- }
-
- $array=list_dir("D:www");
- foreach($array as $value){
- echo $value;
- echo "
";
- }
Copy code
|