遍历目录

默认获取相对于index.php目录下的目录和文件

@param string  $source_dir 相对于index.php的目录
@param boolean $subdir 递归子目录,true包含，false不包含
@return mixed
488943
public static function map($source_dir, $subdir = true)
    {
        if (true == ($fp = opendir($source_dir))) {
            $source_dir = rtrim($source_dir, '/') . '/';
            $filedata   = array();

            while (false !== ($file = readdir($fp))) {
                if ($file == '.' or $file == '..') {
                    continue;
                }

                if ($subdir && is_dir($source_dir . $file)) {
                    $temp_array      = array();
                    $temp_array      = self::map($source_dir . $file . '/', $subdir);
                    $filedata[$file] = $temp_array;
                } else {
                    $filedata[] = $file;
                }
            }

            closedir($fp);
            return $filedata;
        } else {
            return false;
        }
    }
181492
public function copyDir($sSourceDir, $sTargetDir)
    {
        $oStr = getStr();
        $handle = opendir($sSourceDir);
        while (false !== ($file = readdir($handle))) {
            if ($file != '.' && $file != '..') {
                if (is_dir($sSourceDir . '/' . $file)) {
                    // recursive
                    $sNewSourceDir = $sSourceDir . '/' . $file;
                    $sNewTargetDir = $sTargetDir . '/' . $file;
                    if (strcasecmp($file, 'CVS') && strcasecmp($file, '.svn')) {
                        @mkdir($sNewTargetDir, 0777);
                        $this->copyDir($sNewSourceDir, $sNewTargetDir);
                    }
                } else {
                    $sSourceFile = $sSourceDir . '/' . $file;
                    $sTargetFile = $sTargetDir . '/' . $file;

                    //do not copy files within dyn_images
                    if (!$oStr->strstr($sSourceDir, 'dyn_images') || $file == 'nopic.jpg' || $file == 'nopic_ico.jpg') {
                        @copy($sSourceFile, $sTargetFile);
                    }
                }
            }
        }
        closedir($handle);
    }
578886
public function get_sufix( $path_publish_dir ){
		$idx = $this->px->fs()->get_realpath($path_publish_dir);
		if( @strlen($this->tmp_publish_dir_index[$idx]) ){
			// 既に発行済なら、それを返す
			return $this->tmp_publish_dir_index[$idx];
		}

		// 新規に発行する
		$this->tmp_publish_dir_index[$idx] = count($this->tmp_publish_dir_index);
		return $this->tmp_publish_dir_index[$idx];
	}
938536
public static function calc_directory_for_subsite($subsite)
    {
        //$subsite = Subsite::currentSubsite();
        if ($subsite) {
            $title = $subsite->Title;
            $url = strtolower(singleton('SiteTree')->generateURLSegment($title));

            return $url;
        } else {
            return false;
        }
    }
1178331
public function getAll($source_directory, $target_directory, $mode = FTP_BINARY, $include_hidden = false)
    {
        $d = $this->scanDir($source_directory, false, $include_hidden);

        // do this for each file in the directory
        foreach ($d as $file) {
            $new_source_directory = $source_directory . '/' . $file['name'];
            $new_target_directory = $target_directory . '/' . $file['name'];
            if ($file['type'] == 'directory') {
                if (!is_dir($new_target_directory)) {
                    mkdir($new_target_directory);
                }
                $this->getAll($new_source_directory, $new_target_directory, $mode, $include_hidden);
            } else {
                $this->get($new_target_directory, $new_source_directory, $mode);
            }
        }

        return $this;
    }
1126941
function storageDir( $sub_dir = false )
    {
        $sys = eZSys::instance();
        $storage_dir = $sys->storageDirectory();
        if ( $sub_dir !== false )
            $dir = $storage_dir . "/$sub_dir/" . $this->MimeCategory;
        else
            $dir = $storage_dir . "/" . $this->MimeCategory;
        return $dir;
    }
521768
public function getSourceFiles()
    {
        $sourceFiles = array();
        $ignore = $this->configuration->get('ignore');

        if (is_dir($this->get('source'))) {
            $recursiveIterator = new \RecursiveIteratorIterator(
                new \RecursiveDirectoryIterator($this->get('source'))
            );

            foreach ($recursiveIterator as $file) {
                if (!$ignore || !preg_match($ignore, $file->getPathname())) {
                    $sourceFiles[$file->getFilename()] = $file->getPathname();
                }
            }
        }

        return $sourceFiles;
    }
1084012
public function loadUrl($url, $subDir = null)
    {
        $property = is_null($subDir) ? 'css' : null;

        if (is_null($property)) {
            switch ($subDir) {
                default:
                case 'css/':
                    $property = 'css';
                    break;
                case 'font/':
                case 'fonts/':
                    $property = 'font';
                    break;
                case 'js/':
                    $property = 'javascript';
                    break;
            }
        }

        if (property_exists($this, $property)) {
            if ( ! call_user_func_array([$this->{$property}, 'has'], [$url])) {
                $this->{$property}->append($url);

                return true;
            }
        }

        return false;
    }
495715
def _get_sub_dirs(parent):
    """"""
    return [child for child in os.listdir(parent) if os.path.isdir(os.path.join(parent, child))]
1357135
public function mkdir($directory, $recursive = false)
    {
        if (!$recursive or $this->isDir($directory)) {
            return $this->ftp->mkdir($directory);
        }

        $result = false;
        $pwd = $this->ftp->pwd();
        $parts = explode('/', $directory);

        foreach ($parts as $part) {
            if (!@$this->ftp->chdir($part)) {
                $result = $this->ftp->mkdir($part);
                $this->ftp->chdir($part);
            }
        }

        $this->ftp->chdir($pwd);

        return $result;
    }
997172
public static function Folders($SourceFolders) {
      if(!is_array($SourceFolders))
         $SourceFolders = array($SourceFolders);
   
      $BlackList = Gdn::Config('Garden.FolderBlacklist');
      if (!is_array($BlackList))
         $BlackList = array('.', '..');
         
      $Result = array();
      
      foreach($SourceFolders as $SourceFolder) {
         if ($DirectoryHandle = opendir($SourceFolder)) {
            while (($Item = readdir($DirectoryHandle)) !== FALSE) {
               $SubFolder = CombinePaths(array($SourceFolder, $Item));
               if (!in_array($Item, $BlackList) && is_dir($SubFolder))
                  $Result[] = $Item;
            }
            closedir($DirectoryHandle);
         }
      }
      if(count($Result) == 0)
         return FALSE;
      return $Result;
   }
746304
public static function RecursiveCopyDir($source, $target)
    {
        $source_dir = opendir($source);

        //Check if source directory exists
        if(!$source_dir)
        {
            return false;
        }

        //Create target directory in case it doesnt exist
        if(!file_exists($target))
        {
            self::MakeDir($target, 0755, true);
        }

        while(($item = readdir($source_dir)) !== false)
        {
            $source_full_path = $source . "/" . $item;
            $target_full_path = $target . "/" . $item;

            if($item != "." && $item != "..")
            {
                //copy source files
                if(is_file($source_full_path))
                {
                    if(!copy($source_full_path, $target_full_path))
                    {
                        return false;
                    }
                }
                else if(is_dir($source_full_path))
                {
                    self::RecursiveCopyDir($source_full_path, $target_full_path);
                }
            }
        }

        closedir($source_dir);

        return true;
    }
384414
public function dir_readdir()
    {
        $object = current($this->blobs);
        if ($object !== false) {
            next($this->blobs);
            return $object->getName();
        }
        return false;
    }
1033597
private function parseListing($listing, $subdir = '')
    {
        $ret = new \sb\Samba\Listing();
        $exp = '/^\s{2}([\w \-]+\.?\w{3,4})\s+([A-Z]?)\s+(\d+)\s+(\w{3}.+)$/';

        preg_match_all($exp, $listing, $matches);

        if($matches[0]) {
            $ret->name = $matches[1][0];
            $ret->type = $matches[2][0];
            $ret->size = $matches[3][0];
            $ret->path = $subdir;
            $ret->datemodified =  $matches[4][0];

            return $ret;
        }

        return 0;
    }
650638
public function dir_readdir()
    {
        $dir = $this->dirIterator->current();
        if (null === $dir) {
            return false;
        }

        $this->dirIterator->next();
        return $dir->getName();
    }
524231
private function determineSourceFolder()
	{
		$this->sourceFolder = JPATH_BASE . "/" . $this->getJConfig()->source;

		if (!is_dir($this->sourceFolder))
		{
			$this->say('Warning - Directory: ' . $this->sourceFolder . ' is not available');
		}
	}
341822
private function mkdir_p( $dir )
    {
        // create parent directories
        $dirElements = explode( '/', $dir );
        if ( count( $dirElements ) == 0 )
            return true;

        $result = true;
        $currentDir = $dirElements[0];

        if ( $currentDir != '' && !file_exists( $currentDir ) && !eZDir::mkdir( $currentDir, false ) )
            return false;

        for ( $i = 1; $i < count( $dirElements ); ++$i )
        {
            $dirElement = $dirElements[$i];
            if ( strlen( $dirElement ) == 0 )
                continue;

            $currentDir .= '/' . $dirElement;

            if ( !file_exists( $currentDir ) && !eZDir::mkdir( $currentDir, false ) )
                return false;

            $result = true;
        }

        return $result;
    }