Copies all files from package to target directory in project root
- files that already exist are not copied

@return OperationResult
17922
public function install(): OperationResult
    {
        $result = new OperationResult();

        $sourcePath = "{$this->packageInstallDir}/.installer/%s/files";
        foreach ($this->projectType->getProjectDirs() as $projectDir) {
            if (is_dir(sprintf($sourcePath, $projectDir))) {
                /** @var \RecursiveDirectoryIterator $iterator */
                $iterator = new \RecursiveIteratorIterator(
                    new \RecursiveDirectoryIterator(
                        sprintf($sourcePath, $projectDir),
                        \RecursiveDirectoryIterator::SKIP_DOTS
                    ),
                    \RecursiveIteratorIterator::SELF_FIRST
                );

                /** @var \SplFileInfo $file */
                foreach ($iterator as $file) {
                    $target = "{$this->projectRootDir}/{$iterator->getSubPathname()}";
                    if ($file->isDir()) {
                        if (!is_dir($target)) {
                            if (!mkdir($target)) {
                                $result->addErrorMessage("<error>Could not create target directory '${target}'</error>");
                            }
                        }
                    } elseif (!file_exists($target)) {
                        assert(is_string($file->getRealPath()));
                        if (!copy($file->getRealPath(), $target)) {
                            $result->addErrorMessage("<error>Could not copy file to '${target}'</error>");
                        }
                    }
                }
            }
        }

        if (!$result->isFailure()) {
            $result->addStatusMessage("Successfully copied files from package {$this->packageName}");
        }

        return $result;
    }
778175
protected function copyFiles()
    {
        $skeletonFinder = new SkeletonFinder($this->lookupPaths);
        $sourcePath = $skeletonFinder->findByName($this->skeletonName)->getRealpath();

        $finder = $this->getFinderForFilesToCopy($sourcePath);

        foreach ($finder as $file) {
            $targetFilePath = $this->targetPath.DIRECTORY_SEPARATOR.$file->getRelativePathname();
            $targetFilePath = $this->twigStringRenderer->renderToString($targetFilePath, $this->data);

            $this->fs->copy($file->getRealpath(), $targetFilePath, $this->overwriteEnabled);

            $msg = '[copy] '.$file->getRealpath().' => '.$targetFilePath;

            if ($this->reportingEnabled) {
                $this->report[] = $msg;
            }
        }
    }
804178
public function setupProject()
    {
        $this->taskWriteToFile(ProjectX::projectRoot() . '/.gitignore')
            ->text($this->loadTemplateContents('.gitignore.txt'))
            ->place('PROJECT_ROOT', $this->getInstallRoot(true))
            ->run();

        return $this;
    }
106221
private function _createTargetDir()
    {
        if (!$this->_targetDir) {
            return false;
        }
        $targetDir = rtrim($this->_targetDir, '/');
        if (!file_exists($targetDir)) {
            if (!@mkdir($targetDir, 0777, true)) {
                return false;
            }
        }
        return true;
    }
1090054
public static function copy($source, $target, $ignore = null)
    {
        $source = rtrim($source, '\\/');
        $target = rtrim($target, '\\/');

        if (!is_dir($source)) {
            throw new \RuntimeException('Cannot copy non-existing folder.');
        }

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

        $success = true;

        // Go through all sub-directories and copy everything.
        $files = self::all($source);
        foreach ($files as $file) {
            if ($ignore && preg_match($ignore, $file)) {
                continue;
            }
            $src = $source .'/'. $file;
            $dst = $target .'/'. $file;

            if (is_dir($src)) {
                // Create current directory (if it doesn't exist).
                if (!is_dir($dst)) {
                    $success &= @mkdir($dst, 0777, true);
                }
            } else {
                // Or copy current file.
                $success &= @copy($src, $dst);
            }
        }

        if (!$success) {
            $error = error_get_last();
            throw new \RuntimeException($error['message'] ?? 'Unknown error');
        }

        // Make sure that the change will be detected when caching.
        @touch(dirname($target));
    }
1265457
def copy_files(source_files, target_directory, source_directory=None):
    """"""
    try:
        os.makedirs(target_directory)
    except:     # TODO: specific exception?
        pass
    for f in source_files:
        source = os.path.join(source_directory, f) if source_directory else f
        target = os.path.join(target_directory, f)
        shutil.copy2(source, target)
1312760
public function getProjectRoot()
    {
        // Backwards compatibility - if in an old-style project root, change
        // directory to the repository.
        if (is_dir('repository') && file_exists($this->config->get('local.project_config_legacy'))) {
            $cwd = getcwd();
            chdir('repository');
        }

        // The project root is a Git repository, which contains a project
        // configuration file, and/or contains a Git remote with the appropriate
        // domain.
        $dir = $this->findTopDirectoryContaining('.git', function ($dir) {
            $config = $this->getProjectConfig($dir);

            return !empty($config);
        });

        if (isset($cwd)) {
            chdir($cwd);
        }

        return $dir;
    }
102265
protected function _copyDirectory($source, $target)
    {
        $result = false;

        if (!is_dir($target)) {
            $result = mkdir($target, 0755, true);
        }
        else
        {
            // Clear directory
            $iter = new \RecursiveDirectoryIterator($target);
            foreach (new \RecursiveIteratorIterator($iter, \RecursiveIteratorIterator::CHILD_FIRST) as $f)
            {
                if ($f->isDir())
                {
                    if (!in_array($f->getFilename(), array('.', '..'))) {
                        rmdir($f->getPathname());
                    }
                } else {
                    unlink($f->getPathname());
                }
            }
        }

        if (is_dir($target))
        {
            $result = true; // needed for empty directories
            $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source), \RecursiveIteratorIterator::SELF_FIRST);
            foreach ($iterator as $f)
            {
                if ($f->isDir()) {
                    $path = $target.'/'.$iterator->getSubPathName();
                    if (!is_dir($path)) {
                        $result = mkdir($path);
                    }
                } else {
                    $result = copy($f, $target.'/'.$iterator->getSubPathName());
                }

                if ($result === false) {
                    break;
                }
            }
        }

        return $result;
    }
833494
protected function copyModule(): void
    {
        foreach (self::DIRECTORIES as $directory) {
            $this->copy(
                $this->packagePath . DS . $directory . DS,
                PATH_ROOT . DS . $directory . DS
            );
        }

        $this->installer->getIo()->write(
            sprintf(
                '  - Copied <comment>%s</comment> module to application',
                basename($this->packagePath)
            ),
            true
        );
    }
1337940
protected function _copy($source, $targetDir, $name) {
		$res = false;
		
		if ($this->tmp) {
			$local  = $this->getTempFile();
			$target = $targetDir.DIRECTORY_SEPARATOR.$name;

			if (ftp_get($this->connect, $local, $source, FTP_BINARY)
			&& ftp_put($this->connect, $target, $local, $this->ftpMode($target))) {
				$res = $target;
			}
			@unlink($local);
		}
		
		return $res;
	}
197243
private function copyStubsDirectory()
    {
        $path = $this->option('path');

        // if controller stub already exist
        if ($this->files->exists($path . DIRECTORY_SEPARATOR . 'controller.stub') && $this->option('force') === false) {
            $this->error("Stubs already exists! Run 'generate:publish-stubs --force' to override the stubs.");
            die;
        }

        File::copyDirectory(__DIR__ . '/../../resources/stubs', $path);
    }
746304
public static function RecursiveCopyDir($source, $target)
    {
        $source_dir = opendir($source);

        //Check if source directory exists
        if(!$source_dir)
        {
            return false;
        }

        //Create target directory in case it doesnt exist
        if(!file_exists($target))
        {
            self::MakeDir($target, 0755, true);
        }

        while(($item = readdir($source_dir)) !== false)
        {
            $source_full_path = $source . "/" . $item;
            $target_full_path = $target . "/" . $item;

            if($item != "." && $item != "..")
            {
                //copy source files
                if(is_file($source_full_path))
                {
                    if(!copy($source_full_path, $target_full_path))
                    {
                        return false;
                    }
                }
                else if(is_dir($source_full_path))
                {
                    self::RecursiveCopyDir($source_full_path, $target_full_path);
                }
            }
        }

        closedir($source_dir);

        return true;
    }
384045
public function getProjectsRoot() {
    if (!isset($this->projectsRoot)) {
      $this->projectsRoot = new Dir($this->hostConfig->req('projects.root'));
    }
    
    return $this->projectsRoot;
  }
341361
private function copy()
    {
        $source = Yii::getAlias($this->source);
        if (!file_exists($source) || !is_dir($source)) {
            throw new ErrorException("Source directory {$this->source} not found");
        }
        $destination = Yii::getAlias($this->destination);
        if (!$this->replace && is_dir($destination)) { // if replace is disabled we will skip existing files
            $this->keepFiles = FileHelper::findFiles($destination);
        }
        FileHelper::copyDirectory($source, $destination, [
            'except' => ['.git/'],
            'fileMode' => 0775,
            'beforeCopy' => function ($from, $to) {
                return $this->replace || !file_exists($to) || !is_file($to);
            }
        ]);
        return true;
    }
786066
private function copySourceContent()
    {
        // Move plugin to Plugin's directory
        $this->info("Copying source to plugins directory");
        $this->pluginNamespace = str_replace('\\', '/', $this->configContent->namespace);

        if(file_exists(pluginsPath($this->pluginNamespace))) {
            $this->cleanTmp();
            throw new \Exception('A plugin with the same namespace already exists in plugins directory');
        }

        // Created organisation directory if it doesn't exist
        $explodeNamespace = explode('/', $this->pluginNamespace);
        if(!file_exists(pluginsPath($explodeNamespace[0]))) {
            File::makeDirectory(pluginsPath($explodeNamespace[0]), 0755, true);
        }

        // Delete created directory if rename can not be executed
        if(!File::move($this->tmpDirectory, pluginsPath($this->pluginNamespace))) {
            $this->cleanTmp();
            throw new \Exception('Source could not be moved to plugins directory!');
        }

        return $this;
    }
1175401
public function copy($target, $source)
    {
        if (!$this->exists($target)) {
            throw new \RuntimeException("$target does not exist.", E_ERROR);
        }

        if (!$this->exists($source)) {
            $this->makeDirectory(dirname($source), true);
        }

        return file_put_contents($source, $this->get($target));
    }
1224249
protected void copyOtherFiles(File projectDir, File srcDir, File outDir, Replacement replaceFn, Set<String> extraIgnorefiles) throws IOException {
        if (archetypeUtils.isValidFileToCopy(projectDir, srcDir, extraIgnorefiles)) {
            if (srcDir.isFile()) {
                copyFile(srcDir, outDir, replaceFn);
            } else {
                outDir.mkdirs();
                String[] names = srcDir.list();
                if (names != null) {
                    for (String name: names) {
                        copyOtherFiles(projectDir, new File(srcDir, name), new File(outDir, name), replaceFn, extraIgnorefiles);
                    }
                }
            }
        }
    }