Copy all contens of directory to an existing directory
@param string $source
@param string $destination
544202
private function rcopy($source, $destination) { 
	    
	    if(false === is_string($source)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($source)), E_USER_ERROR);
		}

		if(false === is_string($destination)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($destination)), E_USER_ERROR);
		}

		if(false === is_dir($destination)) {

			$tmp = new Directory($destination);
			$tmp -> create();
		}

	    $directory = opendir($source); 
	    
	    while(false !== ($file = readdir($directory))) { 

	        if(false === in_array($file, ['.', '..'])) { 

	            if(is_dir($source . DIRECTORY_SEPARATOR . $file) ) { 
	                $this -> rcopy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); 
	            } 
	            else { 
	                copy($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); 
	            } 
	        } 
	    } 

	    closedir($directory); 
	}
941092
public function recurse_copy($source, $destination)
    {
        $directory = opendir($source);
        $this->fs->mkdir($destination, 0755);
        while (false !== ($file = readdir($directory))) {
            if (($file != '.') && ($file != '..')) {
                if (is_dir($source . '/' . $file)) {
                    $this->recurse_copy($source . '/' . $file, $destination . '/' . $file);
                } else {
                    $this->fs->copy($source . '/' . $file, $destination . '/' . $file);
                }
            }
        }
        closedir($directory);
    }
736788
public function rename($source, $destination) {
        try {
            return $this->getRedis()->rename($source, $destination);
        } catch (RedisException $ex) {
            throw new ConnectException();
        }
    }
310204
public function copy($target, $source)
    {
        $source_stream = $this->readStream($source);
        $result = $this->writeStream($target, $source_stream);

        fclose($source_stream);

        return $result;
    }
1328964
public static function zip($source, $destination) {
		if(!extension_loaded('zip') || !file_exists($source))
			return false;

		$zip = new \ZipArchive();
		if(!$zip->open($destination, \ZIPARCHIVE::CREATE))
			return false;

		$source = str_replace('\\', '/', realpath($source));

		if(is_dir($source)) {
			$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);

			foreach($files as $file) {
				$file = str_replace('\\', '/', realpath($file));

				if(is_dir($file))
					$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
				elseif(is_file($file))
					$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
			}
		}
		elseif(is_file($source))
			$zip->addFromString(basename($source), file_get_contents($source));

		return $zip->close();
	}
296582
public function unpack($source, $destination)
    {
        $this->_setCurrentFile($source)
            ->_setCurrentPath($source);

        $this->_initReader();
        $this->_unpackCurrentTar($destination);
        $this->_destroyReader();

        return $destination;
    }
886089
protected function isEqual($source, $destination)
    {
        if (!ends_with($destination, DIRECTORY_SEPARATOR)) {
            $destination = $destination.DIRECTORY_SEPARATOR;
        }
        if (!ends_with($source, DIRECTORY_SEPARATOR)) {
            $source = $source.DIRECTORY_SEPARATOR;
        }

        if ($destination === $source) {
            throw InvalidParameter::destinationDirectoryIsSource();
        }
    }
598624
public static function copyDir($source, $destination, $permission = 0777, $recursive = true) {
        if (substr($source, strlen($destination) - 1) !== DIRECTORY_SEPARATOR)
            $destination .= DIRECTORY_SEPARATOR;

        try {
            if (!is_dir($destination))
                mkdir($destination, $permission);

            $contents = self::readDir($source, self::ALL, $recursive, NULL);
            if (isset($contents['dirs'])) {
                foreach ($contents['dirs'] as $fullPath) {
                    @mkdir(str_replace(array($source, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR), array($destination, DIRECTORY_SEPARATOR), $fullPath), $permission);
                }
            }

            if (isset($contents['files'])) {
                foreach ($contents['files'] as $fullPathsArray) {
                    foreach ($fullPathsArray as $fullPath) {
                        @copy($fullPath, str_replace(array($source, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR), array($destination, DIRECTORY_SEPARATOR), $fullPath));
                    }
                }
            }
        } catch (\Exception $ex) {
            throw new \Exception($ex->getMessage());
        }
    }
275314
protected function copy($source, $target)
    {
        if (is_file($source)) {
            $exists = is_file($target) ? true :false;
            $this->filesystem->copy($source, $target);

            if (!$exists) {
                return true;
            }
        }

        return false;
    }
263747
public function copy($source, $destination, $override = false)
    {
        if (is_dir($destination) && !is_dir($source)) {
            $destination = rtrim($destination, '/') . '/' . basename($source);
        }
        $this->fs->copy($source, $destination, $override);
    }
1369864
public function copyFiles($source, $target, $files)
    {
        foreach ($files as $file) {
            $this->copyFile($source, $target, $file);
        }
    }
1271237
public function copyAll($source, $target, $mode = null)
    {
        if (is_dir($source)) {
            if ($mode == null) {
                @mkdir($target, Config::get('concrete.filesystem.permissions.directory'));
                @chmod($target, Config::get('concrete.filesystem.permissions.directory'));
            } else {
                @mkdir($target, $mode);
                @chmod($target, $mode);
            }

            $d = dir($source);
            while (false !== ($entry = $d->read())) {
                if (substr($entry, 0, 1) === '.') {
                    continue;
                }

                $Entry = $source . '/' . $entry;
                if (is_dir($Entry)) {
                    $this->copyAll($Entry, $target . '/' . $entry, $mode);
                    continue;
                }

                copy($Entry, $target . '/' . $entry);
                if ($mode == null) {
                    @chmod($target . '/' . $entry, $this->getCreateFilePermissions($target)->file);
                } else {
                    @chmod($target . '/' . $entry, $mode);
                }
            }

            $d->close();
        } else {
            if ($mode == null) {
                $mode = $this->getCreateFilePermissions(dirname($target))->file;
            }
            copy($source, $target);
            chmod($target, $mode);
        }
    }
834143
protected function isDestinationDifferentThanSource($source, $destination)
    {
        $path_parts = pathinfo($destination);
        $this->isEqual($source, $path_parts['dirname']);
    }
383689
protected function _copyDirectory($source, $destination)
    {
        $folder = new Folder($source);
        if ($folder->copy(['to' => $destination])) {
            $this->out('Copied assets to directory ' . $destination);

            return true;
        }

        $this->err('Error copying assets to directory ' . $destination);

        return false;
    }
544258
public function replicateQuoteData($source, $destination)
    {
        // Skip the replication if source and destination point to the same quote
        // E.g. delayed Save Order - immutable quote is cleared by cron and we use the parent instead
        if ($source->getId() == $destination->getId()) return;

        $destinationId = $destination->getId();
        $destinationActive = (bool)$destination->getIsActive();

        $destination->removeAllItems();

        $destination->merge($source);

        $destination->getBillingAddress()->setShouldIgnoreValidation(true);
        $this->transferData($source->getBillingAddress(), $destination->getBillingAddress());

        $destination->getShippingAddress()->setShouldIgnoreValidation(true);
        $this->transferData($source->getShippingAddress(), $destination->getShippingAddress());

        $this->transferData($source, $destination, false);

        $destination->setId($destinationId);
        $destination->setIsActive($destinationActive);

        $this->quoteResourceSave($destination);

        // If Amasty Gif Cart Extension is present clone applied gift cards
        $this->discountHelper->cloneAmastyGiftCards($source->getId(), $destination->getId());
    }
1309237
public function safeRename($source, $destination)
    {
        $isRenamed = @rename($source, $destination);
        if ($isRenamed) {
            return;

        }

        // copy to the target filesystem
        $tempFileOnSameFS = "$destination.tmp";

        $isCopied = copy($source, $tempFileOnSameFS);
        if (! $isCopied) {
            throw new FileException(
                "failed to copy $source to $tempFileOnSameFS."
            );

        }

        $isUnlinked = unlink($source);
        if (! $isUnlinked) {
            trigger_error("Failed to unlink $source.");

        }

        $isRenamed = rename($tempFileOnSameFS, $destination);
        if (! $isRenamed) {
            throw new FileException(
                "failed to rename $tempFileOnSameFS to $destination."
            );

        }
    }
1088964
public function copy($destination) {
    
    if (!$this->exists()) {
      throw new Exception('Source from copy does not exist: '.$this);
    }
    
    if ($destination instanceof Dir) {
      $destination = $destination->getFile($this->getName());
    } elseif (!($destination instanceof File)) {
      throw new InvalidArgumentException('Invalid Argument. $destination must be file or dir');
    }

    if (!$destination->getDirectory()->exists()) {
      throw new Exception('The directory from the destination file does not exist: '.$destination);
    }

    $ret = @copy((string) $this, (string) $destination);

    if (!$ret) {
      throw new Exception('PHP Error while copying '.$this.' onto '.$destination);
    }
    
    return $this;
  }