Copy a directory from one location to another.

@param   string  $path
@param   string  $target
@param   int     $options
@return  bool
977435
public function copyDirectory($path, $target, $options = null)
	{
		$path   = Util::normalizePath($path);
		$target = Util::normalizePath($target);

		$this->assertPresent($path);
		//$this->assertAbsent($target);

		return (bool) $this->adapter->copyDirectory($path, $target, $options);
	}
612577
public function putFile($path, $file, $options = [])
    {
        return $this->putFileAs($path, $file, $file->hashName(), $options);
    }
1267636
private function copyFrom($webroot, $path, $destination = null)
    {
        if (null === $destination) {
            $destination = $path;
            $from = $this->projectRoot . DIRECTORY_SEPARATOR . $path;
        } else {
            // if the destination was defined then we assume the path is either absolute or relative to the webroot
            // because it has been defined by the user in the extra mapping
            $from = $path;
        }

        $to = $this->projectRoot . DIRECTORY_SEPARATOR . $webroot . DIRECTORY_SEPARATOR . $destination;

        $filesystem = $this->getFilesystem();

        if ($filesystem->exists($to)) {
            $filesystem->remove($to);
        }

        $filesystem->symlink($from, $to, true);

        if ($this->io->isVerbose()) {
            $this->io->write(sprintf('Moved %s to %s', $from, $to));
        }
    }
812553
protected function move($sourcePath, $targetPath)
    {
        if ($this->filesystem->has($targetPath)) {
            return false;
        }

        $stream = fopen($sourcePath, 'r+');
        if ($stream === null) {
            return false;
        }

        $success = $this->filesystem->writeStream($targetPath, $stream);

        if (fclose($stream) === false) {
            return false;
        }

        unlink($sourcePath);

        return $success;
    }
180033
public static function copy($file_path = null, $target_path = null, $force = false, array &$logs = array())
    {
        if (is_null($file_path) || is_null($target_path)) {
            return null;
        }
        if (!file_exists($file_path)) {
            $logs[] = sprintf('File path "%s" to copy was not found.', $file_path);
            return false;
        }
        $target_dir = dirname($target_path);
        $ok = (!file_exists($target_dir) && true===$force) ? Directory::create($target_dir) : true;
        if ($ok) {
            if (!file_exists($target_path) || true===$force) {
                if (copy($file_path, $target_path)) {
                    return true;
                } else {
                    $logs[] = sprintf('Can not copy file "%s" to "%s".', $file_path, $target_path);
                }
            } else {
                $logs[] = sprintf('Can not over-write target file "%s" by copy (use param `$force=true`).', $target_path);
            }
        } else {
            $logs[] = sprintf('Can not create target directory "%s" for copy.', $target_dir);
        }
        return false;
    }
893552
public function mkdir($path, $mode, $options)
    {
        if (array_has(self::$folders, $path)) {
            return true;
        }

        $parentEnd = strrpos($path, '/');
        $parent = substr($path, 0, $parentEnd);

        if (array_has(self::$folders, $parent)) {
            self::$folders[] = $path;
            return true;
        }

        if (! ($options & STREAM_MKDIR_RECURSIVE)) {
            return false;
        }

        while ($path !== self::PROTOCOL.':/') {
            if (array_has(self::$folders, $path)) {
                break;
            } else {
                self::$folders[] = $path;
            }

            $path = substr($path, 0, $parentEnd);
            $parentEnd = strrpos($path, '/');
        }

        return true;
    }
77725
private function copyFile(
        FilesystemInterface $source,
        FilesystemInterface $destination,
        $path
    ) {
        $destination->put(
            $path,
            $source->read($path)
        );
    }
513918
public function store($path, $options = [])
    {
        return $this->storeAs($path, $this->hashName(), $this->parseOptions($options));
    }
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;
    }
617837
public function copyRecursive($source, $target, $fileFilter = '/.*/')
    {
        $filesystem = new Filesystem();
        $finder = new Finder();
        $finder->files()->in($source)->name($fileFilter);

        /** @var SplFileInfo $file */
        foreach ($finder as $file) {
            $filesystem->copy($file, $target . DIRECTORY_SEPARATOR . $file->getRelativePathname());
        }
    }
687609
protected function copyDirectory($directory, $destination)
    {
        // Preference is to overwrite existing files
        if ($this->overwrite) {
            return File::copyDirectory($directory, $destination);
        }

        if (!File::isDirectory($directory)) {
            return false;
        }

        $options = FilesystemIterator::SKIP_DOTS;

        if (!File::isDirectory($destination)) {
            File::makeDirectory($destination, 0777, true);
        }

        $items = new FilesystemIterator($directory, $options);

        foreach ($items as $item) {
            $target = $destination.'/'.$item->getBasename();

            if ($item->isDir()) {
                $path = $item->getPathname();

                if (!$this->copyDirectory($path, $target)) {
                    return false;
                }
            }
            else {
                // Do not overwrite existing files
                if (File::isFile($target)) {
                    continue;
                }

                if (!File::copy($item->getPathname(), $target)) {
                    return false;
                }
            }
        }

        return true;
    }
178181
public static function move($source, $target)
    {
        if (!file_exists($source) || !is_dir($source)) {
            // Rename fails if source folder does not exist.
            throw new \RuntimeException('Cannot move non-existing folder.');
        }

        // Don't do anything if the source is the same as the new target
        if ($source === $target) {
            return;
        }

        if (file_exists($target)) {
            // Rename fails if target folder exists.
            throw new \RuntimeException('Cannot move files to existing folder/file.');
        }

        // Make sure that path to the target exists before moving.
        self::create(dirname($target));

        // Silence warnings (chmod failed etc).
        @rename($source, $target);

        // Rename function can fail while still succeeding, so let's check if the folder exists.
        if (!file_exists($target) || !is_dir($target)) {
            // In some rare cases rename() creates file, not a folder. Get rid of it.
            if (file_exists($target)) {
                @unlink($target);
            }
            // Rename doesn't support moving folders across filesystems. Use copy instead.
            self::copy($source, $target);
            self::delete($source);
        }

        // Make sure that the change will be detected when caching.
        @touch(dirname($source));
        @touch(dirname($target));
        @touch($target);
    }
993481
public static void copyDirs(Path source, Path target, CopyOption... options) throws IOException {
        if (Files.notExists(target)) {
            Files.createDirectory(target);
        }

        logger.debug("  --> Copying resources from [{}]", source);
        if (Files.notExists(source)) {
            throw new RuntimeException(source + " doesn't seem to exist.");
        }

        Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
                new InternalFileVisitor(source, target, options));

        logger.debug("  --> Resources ready in [{}]", target);
    }
1265091
public function copyDir($path, $toPath, $nested = false){

        $path = rtrim($path,'/') . '/';
        $toPath = rtrim($toPath,'/') . '/';

        if(!$nested){
            if(!is_dir($toPath) && !mkdir($toPath)){
                return false;
            }//if
            $this->copyDirBasePathLen = strlen($path);
        }//if

        try {

            $iterator = new \DirectoryIterator($path);

            foreach ($iterator as $file) {

                if($file->isDot()){
                    continue;
                }//if

                $newDirPath = $toPath . substr($file->getPathname(),$this->copyDirBasePathLen);

                if($file->isDir() && ((!is_dir($newDirPath) && !mkdir($newDirPath)) || !$this->copyDir($file->getPathname(),$toPath, true))){
                    return false;
                }//if

                if($file->isFile() && !copy($file->getPathname(),$newDirPath)){
                    return false;
                }//if

            }//foreach

        } catch (\Exception $e){
            error_log($e->getMessage());
            return false;
        }//catch

        return true;

    }
873555
public function unpack($target, $options = array()) {
        $results = false;
        if ($this->_archive) {
            if (is_dir($target) && is_writable($target)) {
                $results = $this->_archive->extractTo($target);
            }
        }
        return $results;
    }
377389
public static Optional<Path> moveDir(Path sourceDirPath,
            Path destinationDirPath, CopyOption... options) {
        return operateDir(sourceDirPath, destinationDirPath, sourceDirPath,
                path -> move(path, destinationDirPath, options));
    }
787774
static function copyFile($source, $target, $overwrite = true)
    {
        if (!file_exists($source)) return false;
        if (file_exists($target) && $overwrite == false) return false;
        elseif (file_exists($target) && $overwrite == true) {
            if (!unlink($target)) return false;
        }
        $targetDir = dirname($target);
        if (!self::createDirectory($targetDir)) return false;
        return copy($source, $target);
    }