拷貝文件
@param $source
@param $path
@param $replace
556727
public static function copyFile($source,$dest,$replace=false)
    {
        $dir=dirname($dest);
        if (!file_exists($dir)){//如果文件夹不存在
            self::createDir(dirname($dir));    //取得最后一个文件夹的全路径返回开始的地方
            mkdir($dir, 0777);
            chmod($dir,0777);
        }
        if(file_exists($dest)){
            if($replace)
                unlink($dest);
            else
                return false;
        }
        return copy($source,$dest);
    }
1267764
public function setPath($path, $type = 'replace', $replace = '')
    {
        $oldPath = (!empty($this->url['path']) ? $this->url['path'] : '');

        switch ($type) {
            case 'add':
                $path = $oldPath . $path;
                break;
            case 'remove':
                $path = str_replace($path, '', $oldPath);
                break;
            case 'replace':
            default:
                $path = str_replace($replace, $path, $oldPath);
                break;
        }

        $this->url['path'] = $path;

        return $this;
    }
637411
public function header($header, $value, $replace = true)
    {
        $this->headers[] = array($header, $value, $replace);
    }
1083192
public static Path[] replaceScheme(Path[] paths, String replace, String replacement) {
    if (replace != null && replace.equals(replacement)) {
      return paths;
    }
    Path[] output = new Path[paths.length];
    for (int i = 0; i < paths.length; i++) {
      output[i] = replaceScheme(paths[i], replace, replacement);
    }
    return output;
  }
160941
function replace($search,$replace){
		settype($search,"string");

		// prevod StringBuffer na string
		if(is_object($replace)){
			$replace = $replace->toString();
		}

		for($i=0;$i<sizeof($this->_Buffer);$i++){
			$this->_Buffer[$i]->replace($search,$replace);
		}
	}
1044411
public function replace($path, $content)
    {
        // If the path already exists and is a symlink, get the real path...
        clearstatcache(true, $path);

        $path = realpath($path) ?: $path;

        $tempPath = tempnam(dirname($path), basename($path));

        // Fix permissions of tempPath because `tempnam()` creates it with permissions set to 0600...
        chmod($tempPath, 0777 - umask());

        file_put_contents($tempPath, $content);

        rename($tempPath, $path);
    }
1022102
function copyReplace( src, dest, replacements ){

        if ( replacements ){
            var source = grunt.file.read( src );
            for ( var s in replacements ){
                var r = replacements[s];
                var re = new RegExp( s, "g" );
                source = source.replace( re, r );
            }
            grunt.file.write( dest, source );
        }
        else{
            grunt.file.copy( src, dest );
        }

	}
1200020
public function move($path, $savename = true, $replace = true) {
		// 文件上传失败，捕获错误代码
		if (!empty($this->info['error'])) {
			$this->error($this->info['error']);
			return false;
		}

		// 检测合法性
		if (!$this->isValid()) {
			$this->error = '非法上传文件';
			return false;
		}

		// 验证上传
		if (!$this->check()) {
			return false;
		}
		$path = rtrim($path, DS) . DS;
		// 文件保存命名规则
		$saveName = $this->buildSaveName($savename);
		$filename = $path . $saveName;

		// 检测目录
		if (false === $this->checkPath(dirname($filename))) {
			return false;
		}

		/* 不覆盖同名文件 */
		if (!$replace && is_file($filename)) {
			$this->error = '存在同名文件' . $filename;
			return false;
		}

		/* 移动文件 */
		if ($this->isTest) {
			rename($this->filename, $filename);
		} elseif (!move_uploaded_file($this->filename, $filename)) {
			$this->error = '文件上传保存错误！';
			return false;
		}
		// 返回 File对象实例
		$file = new self($filename);
		$file->setSaveName($saveName);
		$file->setUploadInfo($this->info);
		return $file;
	}
95456
protected function replaceUnEscaped($search, $replace, $subject)
    {
        $search = (array)$search;
        $replace = (array)$replace;

        $patterns = [];

        foreach ($search as $i => $pattern) {
            $patterns[] = "/(?<!\\\\)$pattern/u";
        }

        return preg_replace($patterns, $replace, $subject);
    }
1006933
public function save($file, $replace=true) {
        $filename = $this->rootPath . $file['savepath'] . $file['savename'];

        /* 不覆盖同名文件 */
        // if (!$replace && is_file($filename)) {
        //     $this->error = '存在同名文件' . $file['savename'];
        //     return false;
        // }

        /* 移动文件 */
        if (!ftp_put($this->link, $filename, $file['tmp_name'], FTP_BINARY)) {
            $this->error = '文件上传保存错误！';
            return false;
        }
        return true;
    }
860422
public static function _Save ($image, $path, $replace = FALSE)
	{
		
		// If a file with the same name already exists
		
		if ($replace === FALSE && parent::_Exists ($path))
		{
//			new \Sonic\Message ('error', 'An image with this filename already exists: ' . $path);
			return FALSE;
		}
		
		// Switch new path extension to save file
		
		switch (parent::_getExtension ($path))
		{
			
			// gif
			
			case 'gif':
			
				if (!imagegif ($image, $path))
				{
					return FALSE;
				}
				
				break;
			
			// png
			
			case 'png':
			
				if (!imagepng ($image, $path))
				{
					return FALSE;
				}
				
				break;
				
			// default
				
			default:
				
			
				if (!imagejpeg ($image, $path, 80))
				{
					return FALSE;
				}
				
				break;
			
		}
		
		// Successfully saved, return TRUE
		
		return TRUE;
		
	}
312808
protected function replaceInFile($needle, $replace, $filename)
    {
        if ($filename == '.' || $filename == '..') return;
        file_put_contents( 
            $filename, 
            preg_replace(
                '/' . $needle . '/',
                $replace,
                file_get_contents($filename)
            ) 
        );
    }
1140630
public function replacePath($value, $replace)
    {
        $this->data['path'] = str_replace($value, $replace, $this->data['path']);
        return $this;
    }
1364954
public static function replaceInFile($filename, $replacements){
		$content = \file_get_contents($filename);
		foreach ($replacements as $find => $replace) {
			$content = \str_replace($find, $replace, $content);
		}
		\file_put_contents($filename, $content);
	}
364819
public function copyDirs($source, $target, $dirs)
    {
        foreach ($dirs as $dir) {
            $this->copyDir($source, $target, $dir);
        }
    }
417605
function _replace (regex, replacement, file) {
  const stats = fs.lstatSync(file)
  if (stats.isSymbolicLink()) {
    return
  }
  if (stats.isFile()) {
    let text = fs.readFileSync(file, 'utf-8')
    const ok = typeof regex === 'string' ? text.includes(regex) : regex.test(text)

    if (ok) {
      text = text.replace(regex, replacement)
      console.log(`updating ${relative(file)}`)
      fs.writeFileSync(file, text, 'utf8')
    }
  } else {
    console.log(`${relative(file)} is not a file.`)
  }
}
184248
public static Path replaceScheme(Path path, String replace, String replacement) {
    return new Path(replaceScheme(path.toUri(), replace, replacement));
  }