复制目录
@param $fdir源目录名(不带/)
@param $tdir目标目录名(不带/)
@return
484646
static function dir_copy($fdir, $tdir)
    {
        if (is_dir($fdir)) {
            if (!is_dir($tdir)) {
                mkdir($tdir);
            }
            $handle = opendir($fdir);
            while (false !== ($filename = readdir($handle))) {
                if ($filename != "." && $filename != "..") self::dir_copy($fdir . "/" . $filename, $tdir . "/" . $filename);
            }
            closedir($handle);
            return true;
        } else {
            copy($fdir, $tdir);
            return true;
        }
    }
1343649
protected final static function wipeDir($dir, $rmdir = false) {
		if (file_exists($dir)) {
			$it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
			$files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
			foreach ($files as $file)

				if ($file->isDir())
					self::wipeDir($file->getRealPath(), true); //rmdir($file->getRealPath());
				else
					unlink($file->getRealPath());


			if ($rmdir)
				rmdir($dir);
		}
	}
383540
public static function copy($oldDir, $newDir): bool
    {
        $oldDir = self::pathFormat($oldDir);
        $newDir = self::pathFormat($newDir);

        if (!is_dir($oldDir)) {
            throw new NotFoundException('复制失败：' . $oldDir . ' 不存在！');
        }

        $newDir = self::create($newDir);

        foreach (glob($oldDir . '*') as $v) {
            $newFile = $newDir . basename($v);//文件

            //文件存在，跳过复制它
            if (file_exists($newFile)) {
                continue;
            }

            if (is_dir($v)) {
                self::copy($v, $newFile);
            } else {
                copy($v, $newFile);//是文件就复制过来
                @chmod($newFile, 0664);// 权限 0777
            }
        }

        return true;
    }
140011
protected function buildResourceWatcher($sourceDir, $destinationDir)
    {
        $fs = new Filesystem();
        $relativeDestination = rtrim($fs->makePathRelative($destinationDir, $sourceDir), '/');

        $finder = new Finder();
        $finder->files()
            ->name('*.*')
            ->in($sourceDir);

        if (false === strpos($relativeDestination, '..')) {
            $finder->exclude($relativeDestination);
        }

        $rc = new ResourceCacheMemory();
        $rw = new ResourceWatcher($rc);
        $rw->setFinder($finder);

        return $rw;
    }
700198
public static function createDir($dir, $mode = 0775)
    {
        if (empty($dir)) return false;
        if (!is_dir($dir)) {
            if(@mkdir($dir, $mode, true)){
                return true;
            }else{
                return false;
            }
        } else {
           return true;
        }
    }
1284068
protected function syncDir($originDir, $targetDir)
    {
        if (is_dir($originDir)) {
            $this->output->writeln(
                sprintf('Installing files for <comment>%s</comment> into <comment>%s</comment>', $originDir, $targetDir)
            );

            $this->filesystem->remove($targetDir);

            if ($this->mode != self::MODE_COPY) {
                if ($this->mode == self::MODE_RELATIVE) {
                    $relativeOriginDir = $this->filesystem->makePathRelative($originDir, realpath(dirname($targetDir)));
                } else {
                    $relativeOriginDir = $originDir;
                }
                $relativeOriginDir = rtrim($relativeOriginDir, DIRECTORY_SEPARATOR);
                $this->filesystem->symlink($relativeOriginDir, $targetDir);
            } else {
                if (!is_dir($targetDir)) {
                    $this->filesystem->mkdir($targetDir, 0777);
                }
                $this->filesystem->mirror(
                    $originDir,
                    $targetDir,
                    Finder::create()->ignoreDotFiles(false)->in($originDir)
                );
            }
        } else {
            $this->output->writeln(
                sprintf('Installing file <comment>%s</comment> into <comment>%s</comment>', $originDir, $targetDir)
            );

            $this->filesystem->remove($targetDir);

            if ($this->mode != self::MODE_COPY) {
                if ($this->mode == self::MODE_RELATIVE) {
                    $relativeOriginDir =
                        $this->filesystem->makePathRelative(dirname($originDir), realpath(dirname($targetDir))) .
                        DIRECTORY_SEPARATOR .
                        basename($originDir);
                } else {
                    $relativeOriginDir = $originDir;
                }
                $this->filesystem->symlink($relativeOriginDir, $targetDir);
            } else {
                if (!is_dir($targetDir)) {
                    $this->filesystem->mkdir(dirname($targetDir), 0777);
                }
                $this->filesystem->copy($originDir, $targetDir);
            }
        }
    }
1256473
static function recursiveFindRelative( $baseDir, $subDir, $suffix )
    {
        $dir = $baseDir;
        if ( $subDir != "" )
        {
            if ( $dir != '' )
                $dir .= "/" . $subDir;
            else
                $dir .= $subDir;
        }

        if ( !is_dir( $dir ) )
        {
            return array();
        }

        $returnFiles = array();
        if ( $handle = @opendir( $dir ) )
        {
            while ( ( $file = readdir( $handle ) ) !== false )
            {
                if ( ( $file == "." ) || ( $file == ".." ) )
                {
                    continue;
                }
                if ( is_dir( $dir . '/' . $file ) )
                {
                    if ( $file[0] != "." )
                    {
                        $files = eZDir::recursiveFindRelative( $baseDir, $subDir . '/' . $file, $suffix );
                        $returnFiles = array_merge( $files, $returnFiles );
                    }
                }
                else
                {
                    if ( preg_match( "/$suffix$/", $file ) )
                        $returnFiles[] = $subDir . '/' . $file;
                }
            }
            @closedir( $handle );
        }
        return $returnFiles;
    }
701006
private function loadLocales($inputDir)
    {
        $localeList = array();

        foreach (scandir($inputDir) as $item) {
            if (substr($item, 0, 1) !== '.' && is_dir($inputDir . $item)) {
                if (in_array($item, $this->ignoredLocales)) {
                    // Skip over any ignored locales
                    continue;
                }

                $localeList[] = $item;
            }
        }

        return $localeList;
    }
1048657
def create_tmpdir
      td = tls[:tmpdir]
      if td.nil?
        td = ::Dir.mktmpdir
        tls[:tmpdir] = td
        created = true
      else
        created = false
      end
      return [td, created]
    end
9347
public function getFilesOfDir($dir)
    {
        $iterator = new DirectoryIterator($dir);

        $iterator = new CallbackFilterIterator(
            $iterator,
            function (SplFileInfo $current, $key, DirectoryIterator $iterator) {
                return !$iterator->isDot();
            }
        );

        return $iterator;
    }
675116
public static function listDirs($pDir)
    {
        if (substr($pDir, -1) !== DS) {
            $pDir .= DS;
        }

        $content = glob($pDir . '*', GLOB_ONLYDIR);
        if ($content === false) {
            return array();
        }

        $content = array_map(function($el) use ($pDir) {
            //return str_replace($pDir, '', $el);
            return $el . DS;
        }, $content);

        return $content;
    }
664887
public function ls($subdir = '', &$raw = NULL)
    {

        $teststr  = str_replace('\\', '-', $subdir);
        $nub =  (preg_match('/[-?|\/?]*([\w \-]+\.\w{1,4})/', $teststr))?'':'\*';

        $this->execute("ls $subdir".$nub, $raw_ls);

        $raw = $raw_ls;
        $ret = ($raw_ls)? $this->processLS($raw_ls, $subdir):0;
        return $ret;
    }
372627
public function getCacheDir()
    {
        $dir=$this->m_cacheDir;
        if(empty($dir)){
            $dir=__DIR__."/../../../../../../_cache";
        }
        if(!file_exists($dir)){
            File::createDir($dir);
        }
        return rtrim($dir)."/";
    }
590969
public function getDir($directory)
    {
        $directory = str_replace('/', DS, $directory);
        if (strpos($directory, $this->getBaseDir()) === false || !file_exists($directory)) {
            $directory = $this->getBaseDir() . DS . ltrim($directory, DS);
        }
        return $directory;
    }
538102
function _nlist_helper($dir, $recursive, $relativeDir)
    {
        $files = $this->_list($dir, false);

        if (!$recursive || $files === false) {
            return $files;
        }

        $result = array();
        foreach ($files as $value) {
            if ($value == '.' || $value == '..') {
                if ($relativeDir == '') {
                    $result[] = $value;
                }
                continue;
            }
            if (is_array($this->_query_stat_cache($this->_realpath($dir . '/' . $value)))) {
                $temp = $this->_nlist_helper($dir . '/' . $value, true, $relativeDir . $value . '/');
                $result = array_merge($result, $temp);
            } else {
                $result[] = $relativeDir . $value;
            }
        }

        return $result;
    }
1280902
public static function delDir($dir) {
        $all = self::readDir($dir, self::ALL, true, NULL);
        if (isset($all['files'])) {
            foreach ($all['files'] as $file) {
                if (is_array($file)) {
                    foreach ($file as $fil) {
                        if (!unlink($fil)) {
                            return false;
                        }
                    }
                } else {
                    if (!unlink($file)) {
                        return false;
                    }
                }
            }
        }

        if (isset($all['dirs'])) {
            foreach (array_reverse($all['dirs']) as $_dir) {
                if (is_array($_dir)) {
                    foreach ($_dir as $_dr) {
                        if (!rmdir($_dr)) {
                            return false;
                        }
                    }
                } else {
                    if (!rmdir($_dir)) {
                        return false;
                    }
                }
            }
        }

        return rmdir($dir);
    }
475750
public File getDir(String subDir) {
		File dir = new File(getDir(), subDir);
		dir.mkdirs();
		return dir;
	}