Get a new unique filename if file exists.
@param  string $dst
@return string
503719
public static function getNewFilename($dst) {
		$fileexts = explode('.', $dst);
		if(count($fileexts) > 1) {
			$filename = implode('.', array_slice($fileexts, 0, -1));
			$ext = $fileexts[count($fileexts)-1];
			$dst = $filename.'.'.$ext;
		}
		else
			$filename = $dst;

		$i=1;
		while(file_exists($dst))
			$dst = $filename.'_'.($i++).(isset($ext) ? '.'.$ext:'');

		return $dst;
	}
603069
public function renameRow(string $src, string $dst): bool
    {
        if ($this->hasKey($dst)) {
            throw new \RuntimeException("Cannot rename object: key '{$dst}' is already taken");
        }

        if (!$this->hasKey($src)) {
            return false;
        }

        return $this->moveFolder($this->getMediaPath($src), $this->getMediaPath($dst));
    }
304034
public function mkfile($dst, $name) {
		if ($this->commandDisabled('mkfile')) {
			return $this->setError(elFinder::ERROR_PERM_DENIED);
		}
		
		if (!$this->nameAccepted($name)) {
			return $this->setError(elFinder::ERROR_INVALID_NAME);
		}
		
		if (($dir = $this->dir($dst)) == false) {
			return $this->setError(elFinder::ERROR_TRGDIR_NOT_FOUND, '#'.$dst);
		}
		
		$path = $this->decode($dst);
		
		if (!$dir['write'] || !$this->allowCreate($path, $name, false)) {
			return $this->setError(elFinder::ERROR_PERM_DENIED);
		}
		
		if ($this->stat($this->joinPathCE($path, $name))) {
			return $this->setError(elFinder::ERROR_EXISTS, $name);
		}
		
		$this->clearcache();
		return ($path = $this->convEncOut($this->_mkfile($this->convEncIn($path), $this->convEncIn($name)))) ? $this->stat($path) : false;
	}
880895
public function getSafeFileName()
    {
        $fileExtension = pathinfo($this->file->getClientOriginalName(), PATHINFO_EXTENSION);
        $mimeTypeExtension = $this->file->guessExtension();
        $newExtension = !empty($mimeTypeExtension) ? $mimeTypeExtension : $fileExtension;

        $baseName = !empty($fileExtension) ? basename($this->file->getClientOriginalName(), $fileExtension) : $this->file->getClientOriginalName();
        $safeBaseName = Transliterator::urlize($baseName);

        return $safeBaseName . (!empty($newExtension) ? '.' . $newExtension : '');
    }
965814
public static function uniqueFilename($filename, $path) {
	
		// fixes path if not containing trailing slash
		self::fixTrailingSlash($path);
	
		if (file_exists($path . $filename)) {
			$dot  = strrpos($filename,'.');
			$ext  = substr($filename,$dot);
			$name = substr($filename,0,$dot);
			$hash = substr(md5(time()),0,6);
			$filename = $name . '-' . $hash . $ext;
		}
	
		return $filename;
	
	}
438163
public function copy($dst, $mode=null) {
		$dst = \Asgard\File\FileSystem::copy($this->src, $dst, $mode);
		if($dst) {
			$copy = clone $this;
			$copy->setSrc($dst);
			return $copy;
		}
		return false;
	}
480459
protected static function getUniqueReleaseName($release)
    {
        // Prevent duplicate release names
        $i = 0;
        $releaseName = $release;
        $cmdTemplate = '[ -d {{deploy_path}}/releases/%s ]';
        $cmd = sprintf($cmdTemplate, $releaseName);
        while (\Deployer\test($cmd)) {
            $releaseName = $release . '-' . ++$i;
            $cmd = sprintf($cmdTemplate, $releaseName);
        }

        return $releaseName;
    }
677870
def getNonexistingFile(name):
    
    num = 1
    stem, ext = os.path.splitext(name)
    filename = name
    while os.path.exists(filename):
        suffix = "-%d" % num
        filename = stem + suffix + ext
        num += 1
    return filename
843181
protected static function copyDir($src, $dst, $mode=null) {
		if($mode === null)
			$mode = static::OVERRIDE;

		if(file_exists($dst)) {
			if($mode & static::MERGEDIR) {}
			elseif($mode & static::RENAME)
				$dst = static::getNewFilename($dst);
			elseif($mode & static::OVERRIDE)
				static::delete($dst);
		}

		$r = true;
		$dir = opendir($src);
		static::mkdir($dst);
		while(false !== ($file = readdir($dir))) {
			if(($file != '.') && ($file != '..'))
				$r = $r && static::copy($src.'/'.$file, $dst.'/'.$file, $mode);
		}
		closedir($dir);

		if($r !== false)
			return $dst;
		return false;
	}
1005113
public function parseToFile($dst, $data)
    {
        $pattern = new Pattern($this->src);
        return file_put_contents($dst, $pattern->parse($data));
    }
936674
private function __copyDir($src, $dst, &$files = null)
    {
        $dir = opendir($src);
        @mkdir($dst);
        while (false !== ($file = readdir($dir))) {
            if (('.' != $file) && ('..' != $file)) {
                if (is_dir($src.'/'.$file)) {
                    $this->__copyDir($src.'/'.$file, $dst.'/'.$file, $files);
                } else {
                    copy($src.'/'.$file, $dst.'/'.$file);
                    if (\is_array($files)) {
                        $files[] = $dst.'/'.$file;
                    }
                }
            }
        }
        closedir($dir);
    }
992647
private function recursiveCopy($src, $dst)
    {
        @mkdir($dst, 0755);

        $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS),
            \RecursiveIteratorIterator::SELF_FIRST
        );

        foreach ($iterator as $file) {
            if ($file->isDir()) {
                @mkdir($dst.'/'.$iterator->getSubPathName());
            } else {
                $success = copy($file, $dst.'/'.$iterator->getSubPathName());
                if ($success) {
                    if (! $this->silent) {
                        echo 'copied: '.$dst.'/'.$iterator->getSubPathName().PHP_EOL;
                    }
                }
            }
        }
    }
730074
public static function copyDir($src, $dst) {
        if ( is_file($src) ) {  //如果是文件，则直接拷贝
            return copy($src, $dst);
        }
        @mkdir($dst);   //创建目标目录
        $handle = opendir($src);
        if ( $handle !== false ) {
            while( ($filename = readdir($handle)) ) {

                if ( $filename == '.'  || $filename == '..' ) continue;
                $fileSrc = $src.'/'.$filename;
                $fileDst = $dst.'/'.$filename;
                if ( is_dir($fileSrc) ) {
                    self::copyDir($fileSrc, $fileDst);
                } else {
                    copy($fileSrc, $fileDst);
                }

            }
        }
        closedir($src);
    }
166583
public function generateUniqueFilename($filename)
    {
        if (!is_string($filename) && !is_array($filename)) {
            throw new \InvalidArgumentException(sprintf(
                'The target must be a string or an array from [pathfino()], received %s',
                (is_object($filename) ? get_class($filename) : gettype($filename))
            ));
        }

        if (is_string($filename)) {
            $info = pathinfo($filename);
        } else {
            $info = $filename;
        }

        $filename = $info['filename'].'-'.uniqid();

        if (isset($info['extension']) && $info['extension']) {
            $filename .= '.'.$info['extension'];
        }

        return $filename;
    }
304443
public function rename(string $srcPath, string $dstPath): ?Virtual
    {
        $changes = $this->getChanges();

        $srcEntity = $this->getEntity($srcPath);
        $dstEntity = $this->getEntity($dstPath);

        if (null === $srcEntity || !$srcEntity->file_exists()) {
            $result = null;
        } elseif (null === $dstEntity || $dstEntity->file_exists()) {
            $result = null;
        } else {
            if ($srcEntity->is_dir()) {
                $dirStat = $this->getStat($srcPath, 0);
                $dstEntity = $this->makeDirectory($dstPath, $dirStat['mode'], 0);

                $list = $this->getList($srcPath);
                if (count($list)) {
                    foreach ($list as $file) {
                        $filename = $file->basename();
                        $this->rename(
                            $srcPath.'/'.$filename,
                            $dstPath.'/'.$filename
                        );
                    }
                }
            } else {
                $tmpPath = $this->tempnam();
                copy($srcEntity->path(), $tmpPath);

                $dstEntity = Virtual::newInstance(
                    $dstEntity, $tmpPath, $dstEntity->basename()
                );
                $changes->add($dstPath, $dstEntity);
            }

            $srcEntity = Deleted::newInstance($srcEntity);
            $changes->add($srcPath, $srcEntity);

            $result = $dstEntity;
        }

        return $result;
    }
1235401
private function getNewDateFileName($timestamp)
    {
        $this->currentFileDateTime = $timestamp;
        $this->currentFileIndex = 0;
        $this->currentNoIndexFileName = $this->replaceDateTime($this->fileName, $timestamp);
        $this->currentFileExt = pathinfo($this->currentNoIndexFileName, PATHINFO_EXTENSION);
        return $this->currentNoIndexFileName = substr($this->currentNoIndexFileName, 0, -strlen($this->currentFileExt));
    }
864308
public function uniqueName($dir, $name, $suffix = ' copy', $checkNum=true) {
		$ext  = '';

		if (preg_match('/\.((tar\.(gz|bz|bz2|z|lzo))|cpio\.gz|ps\.gz|xcf\.(gz|bz2)|[a-z0-9]{1,4})$/i', $name, $m)) {
			$ext  = '.'.$m[1];
			$name = substr($name, 0,  strlen($name)-strlen($m[0]));
		} 
		
		if ($checkNum && preg_match('/('.$suffix.')(\d*)$/i', $name, $m)) {
			$i    = (int)$m[2];
			$name = substr($name, 0, strlen($name)-strlen($m[2]));
		} else {
			$i     = 1;
			$name .= $suffix;
		}
		$max = $i+100000;

		while ($i <= $max) {
			$n = $name.($i > 0 ? $i : '').$ext;

			if (!$this->stat($this->_joinPath($dir, $n))) {
				$this->clearcache();
				return $n;
			}
			$i++;
		}
		return $name.md5($dir).$ext;
	}