File_Find::_build PHP Méthode

_build() public méthode

internal function to build singular directory trees, used by File_Find::maptree()
public _build ( string $directory, string $separator = "/" ) : void
$directory string name of the directory to read
$separator string directory separator
Résultat void
    function _build($directory, $separator = "/")
    {
        $dh = @opendir($directory);
        if (!$dh) {
            $pe = PEAR::raiseError("Cannot open directory");
            return $pe;
        }
        while (false !== ($entry = @readdir($dh))) {
            if ($entry != '.' && $entry != '..') {
                $entry = $directory . $separator . $entry;
                if (is_dir($entry)) {
                    array_push($this->_dirs, $entry);
                } else {
                    array_push($this->files, $entry);
                }
            }
        }
        @closedir($dh);
    }

Usage Example

Exemple #1
0
 /**
  * Map the directory tree given by the directory_path parameter.
  *
  * @param string $directory contains the directory path that you
  * want to map.
  *
  * @return array a two element array, the first element containing a list
  * of all the directories, the second element containing a list of all the
  * files.
  *
  * @author Sterling Hughes <*****@*****.**>
  * @access public
  */
 function &maptree($directory)
 {
     /* if called statically */
     if (!isset($this) || !is_a($this, "File_Find")) {
         $obj = new File_Find();
         return $obj->maptree($directory);
     }
     /* clear the results just in case */
     $this->files = array();
     $this->directories = array();
     /* strip out trailing slashes */
     $directory = preg_replace('![\\\\/]+$!', '', $directory);
     $this->_dirs = array($directory);
     while (count($this->_dirs)) {
         $dir = array_pop($this->_dirs);
         File_Find::_build($dir, $this->dirsep);
         array_push($this->directories, $dir);
     }
     sort($this->directories);
     sort($this->files);
     $retval = array($this->directories, $this->files);
     return $retval;
 }
All Usage Examples Of File_Find::_build