| AND OR | string words | *

directories

|

recursive directory listing


a function to scan directories recursively and save the result to an array
with informations like level, path, name and file informations.


function recur_dir( ) [ line 2 ]



full source of recursive directory listing [ line 1 - 37 ] | download recursive directory listing

1    <?php
2   function recur_dir($dir)
3   {
4       $dirlist opendir($dir);
5       while ($file readdir ($dirlist))
6       {
7           if ($file != '.' && $file != '..')
8           {
9               $newpath $dir.'/'.$file;
10               $level explode('/',$newpath);
11               if (is_dir($newpath))
12               {
13                   $mod_array[] = array(
14                           'level'=>count($level)-1,
15                           'path'=>$newpath,
16                           'name'=>end($level),
17                           'kind'=>'dir',
18                           'mod_time'=>filemtime($newpath),
19                           'content'=>recur_dir($newpath));
20               }else{
21                   $mod_array[] = array(
22                           'level'=>count($level)-1,
23                           'path'=>$newpath,
24                           'name'=>end($level),
25                           'kind'=>'file',
26                           'mod_time'=>filemtime($newpath),
27                           'size'=>filesize($newpath));
28              }
29           }
30       }
31       closedir($dirlist); 
32       return $mod_array;
33   }
34   echo '<pre>';
35   print_r(recur_dir('.'));
36   echo '</pre>';
37   ?>



21 hits by 16 users in the last 30 minutes.