Re: Accidental duplicate note added to open_dir function note section

From: Date: Thu, 22 Dec 2005 01:18:26 +0000
Subject: Re: Accidental duplicate note added to open_dir function note section
References: 1  Groups: php.mirrors 
Request: Send a blank email to php-mirrors+get-30151@lists.php.net to get a copy of this message
I've deleted the note. Regards, Nuno ----- Original Message ----- From: "Mike Stabile" <mstabile75@gmail.com> To: <webmaster@php.net> Sent: Wednesday, December 21, 2005 9:12 PM Subject: Accidental duplicate note added to open_dir function note section I have accidentally submitted the same note twice to the note section of "open_dir" funtion page. Only the first note has shown up so far. If you could delete the second/duplicate if your page does not automatically delete the duplicate note. The first note's email was: mstabile75 at gmail dot com The duplicate's was: mstabile75@gmail.com Sorry for the inconvienence. Thanks, Mike The added note was: <?php /* The below function will list all folders and files with in a directory It is a function with a recursive subfunction within. The reason I used a subfunction is because I did not know how to properly pass variables within a recursive function. *This function has no limit on the number of levels down you can search. *This was the cleanest method I could come up with. *The array structure was one that worked for me. ARGUMENTS: $startdir => specify the directory to start from; format: must end in a "/" $searchSubdirs => True/false; True if you want to search subdirectories $directoriesonly => True/false; True if you want to only return directories $maxlevel => "all" or a number; specifes the number of directories down that you want to search */ function filelist($startdir="./", $searchSubdirs=1, $directoriesonly=0, $maxlevel="all") { global $ignoredDirectory, $directorylist; //list the directory names that you want to ignore $ignoredDirectory[] = "."; $ignoredDirectory[] = ".."; $ignoredDirectory[] = "_vti_cnf";
   //$directorylist = array();    //define $directorylist to be used by
function filesearch
       function filesearch ($startdir="./", $searchSubdirs=1,
$directoriesonly=0, $level=1, $maxlevel) {
           //subfuntion that searched through the directories
               global $ignoredDirectory, $directorylist;    //initialize
globals in subfunction
               if (is_dir($startdir)) { //if the directory exists start
                   if ($dh = opendir($startdir)) { //if you can open the
directory continue
                           while (($file = readdir($dh)) !== false) {
//while there are items in the directory
                               if (!(array_search($file,$ignoredDirectory)
-1)) {
                                   //test to see if it is one of the
ignored directories
                                  $parentarray = explode("/",$startdir);
                                  //these 2 lines will parse out the parent
folder
                                  $parent =
$parentarray[(count($parentarray)-2)];
                                  if (filetype($startdir . $file) == "dir")
{
                                      //the current item is a directory
                                          //build your directory array
however you choose; add other file details that you want.
                                          $directorylist[$startdir .
$file]['level'] = $level;
                                          $directorylist[$startdir .
$file]['dir'] = 1; $directorylist[$startdir . $file]['name'] = $file;
                                          $directorylist[$startdir .
$file]['path'] = $startdir; $directorylist[$startdir . $file]['parent'] = $parent;
                                          if ($searchSubdirs) {
                                              if ((($maxlevel) == "all") or
($maxlevel > $level)) {
                                                  filesearch($startdir .
$file . "/", $searchSubdirs, $directoriesonly, $level + 1, $maxlevel);
                                              }
                                          }
                                  } else {
                                      if (!$directoriesonly) { //if you
want to include files
                                          //build your file array however
you choose; add other file details that you want.
                                          $directorylist[$startdir .
$file]['level'] = $level; $directorylist[$startdir . $file]['dir'] = 0;
                                          $directorylist[$startdir .
$file]['name'] = $file; $directorylist[$startdir . $file]['path'] = $startdir;
                                          $directorylist[$startdir .
$file]['parent'] = $parent;
                     }}}}
                        closedir($dh);
       }}}
       filesearch($startdir, $searchSubdirs, $directoriesonly,1,
$maxlevel);
       return($directorylist);
} // call the function $files = filelist("./",1,0,4); foreach ($files as $list) {//print array echo key($files) . "<br>"; //the key is the fullpath and filename. For some reason this "echo" adds "Array" at the beginning of the key echo "Directory: " . $list['dir'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Parent: " . $list['parent'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Level: " . $list['level'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name: " . $list['name'] . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Path: " . $list['path'] ."<br>"; echo next($files); }?>

« previous php.mirrors (#30151) next »