Recursive path copy for php.

@param  string  $start_path
@param  string  $copy_path
@return boolean
4351
public static function copy($start_path, $copy_path, $dir_mode = 0777)
    {
        $return = mkdir($copy_path, $dir_mode, true);
        $files = self::getContent($start_path);
        foreach ($files as $file) {
            if (is_dir($start_path.DIRECTORY_SEPARATOR.$file)) {
                $return = self::copy(rtrim($start_path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file, $copy_path.DIRECTORY_SEPARATOR.$file, $dir_mode);
            } else {
                $return = copy(rtrim($start_path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.$file, $copy_path.DIRECTORY_SEPARATOR.$file);
            }
        }

        return $return;
    }
1059885
public function copyFolder($originalPath, $newPath)
    {
        $disk = $this->getStorageDisk();

        $copyDirectory = function ($srcPath, $destPath) use (&$copyDirectory, $disk) {
            $srcPath = self::validatePath($srcPath);
            $fullSrcPath = $this->getMediaPath($srcPath);

            $destPath = self::validatePath($destPath);
            $fullDestPath = $this->getMediaPath($destPath);

            if (!$disk->makeDirectory($fullDestPath)) {
                return false;
            }

            $folderContents = $this->scanFolderContents($fullSrcPath);

            foreach ($folderContents['folders'] as $dirInfo) {
                if (!$copyDirectory($dirInfo->path, $destPath.'/'.basename($dirInfo->path))) {
                    return false;
                }
            }

            foreach ($folderContents['files'] as $fileInfo) {
                $fullFileSrcPath = $this->getMediaPath($fileInfo->path);

                if (!$disk->copy($fullFileSrcPath, $fullDestPath.'/'.basename($fileInfo->path))) {
                    return false;
                }
            }

            return true;
        };

        return $copyDirectory($originalPath, $newPath);
    }
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);
	}
688527
def copy_file(self, from_path, to_path, replace=False):
        
        f = self.get_file(from_path)
        if f.copy(to_path, replace):
            self.set_cache_buster(to_path, f.hash())
410471
private function recursiveScan($startFolder) {
		if (is_file($startFolder)) {
			$this->files[] = $startFolder;
			return;
		}
		$contents = scandir($startFolder);
		foreach ($contents as $content) {
			if (strpos($content, '.') === 0) {
				continue;
			}

			$path = $startFolder.DIRECTORY_SEPARATOR.$content;
			if (is_dir($path)) {
				$this->recursiveScan($path);
			} else {
				$fileExtension = pathinfo($content, PATHINFO_EXTENSION);
				if (strlen($fileExtension) == 0 || !in_array($fileExtension, $this->getFileExtensions())) {
					continue;
				}
				$this->files[] = $path;
			}
		}
	}
920681
function split($start, $length = null)
    {
        $return = clone $this;
        $path   = array_slice($this->getPath(), $start, $length);
        $return->setPath($path);

        return $return;
    }
801103
public function copy($path, $newpath)
    {
        $command = $this->s3Client->getCommand(
            'copyObject',
            [
                'Bucket'     => $this->bucket,
                'Key'        => $this->applyPathPrefix($newpath),
                'CopySource' => urlencode($this->bucket . '/' . $this->applyPathPrefix($path)),
                'ACL'        => $this->getRawVisibility($path) === AdapterInterface::VISIBILITY_PUBLIC
                    ? 'public-read' : 'private',
            ] + $this->options
        );

        try {
            $this->s3Client->execute($command);
        } catch (S3Exception $e) {
            return false;
        }

        return true;
    }
359174
public function copy($src, $rel_path){
		$path = $this->setDir($rel_path);
		if( !($exist = file_exists($src)) ){
			trigger_error(sprintf('File %s doesn\'t exist.', $src), E_USER_WARNING);
		}
		return $path && $exist && copy($src, $path)
			? $path
			: false;
	}
991115
protected StringBuilder getPath(StringBuilder path, int startIndex, boolean addPoint) {
		boolean simple = true;
		if (key != null) {
			if (addPoint && path.length() > 0) {
				path.insert(0, '.');
			}
			if (key instanceof Integer) {
				path.insert(0, ']');
				if (startIndex == 0) {
					path.insert(0, key);
				} else {
					path.insert(0, startIndex + (int) key);
				}
				path.insert(0, '[');
				simple = false;
			} else {
				path.insert(0, key);
			}
		}
		if (parent != null) {
			parent.getPath(path, startIndex, simple);
		}
		return path;
	}
336941
public static function copy(string $path, string $newpath, bool $recursive = false)
    {
        if ($recursive) {

            if (!Filesystem::has($newpath)) {
                mkdir($newpath);
            }

            $splFileInfoArr = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path), \RecursiveIteratorIterator::SELF_FIRST);

            foreach ($splFileInfoArr as $fullPath => $splFileinfo) {
                //skip . ..
                if (in_array($splFileinfo->getBasename(), [".", ".."])) {
                    continue;
                }

                //get relative path of source file or folder
                $_path = str_replace($path, "", $splFileinfo->getPathname());

                if ($splFileinfo->isDir()) {
                    mkdir($newpath."/".$_path);
                } else {
                    copy($fullPath, $newpath."/".$_path);
                }
            }
        } else {
            return copy($path, $newpath);
        }
    }
798307
public function findMagentoRootDir($start_directory)
    {
        $ds = DIRECTORY_SEPARATOR;
        $directory_tree = explode($ds, $start_directory);

        while (count($directory_tree) > 0) {
            $current_directory = join($ds, $directory_tree);
            $current_search_location = join($ds, array_merge($directory_tree, array('app', 'Mage.php')));

            if (file_exists($current_search_location)) {
                return $current_directory;
            }

            array_pop($directory_tree);
        }

        throw new \Exception("Unable to locate Magento root");
    }
389663
protected function copyFiles($fromPath, $toPath, $namespace)
    {
        // trim paths
        $fromPath = rtrim($fromPath, "/\\");
        $toPath = rtrim($toPath, "/\\");

        // get files recursively
        $filePaths = $this->glob_recursive($fromPath . "/*");

        // generate new files
        $results = [];
        foreach ($filePaths as $file) {

            // skip directories
            if (is_dir($file)) {
                continue;
            }

            // calculate new file path and relative file
            $newFilePath = str_replace($fromPath, $toPath, $file);
            $relativeFile = str_replace($fromPath, "", $file);

            // get file content and replace namespace
            $content = file_get_contents($file);
            $content = str_replace("amnah\\yii2\\user", $namespace, $content);

            // save and store result
            if (file_exists($newFilePath)) {
                $results[$relativeFile] = "File already exists ... skipping";
            } else {
                $result = $this->save($newFilePath, $content);
                $results[$relativeFile] = ($result === true ? "success" : $result);
            }
        }

        print_r($results);
    }
410190
def copy_file(self, path):
        
        if "*" in path:
            paths = _expand_paths(path)
            if paths:
                for path in paths:
                    self._copy_file(path)
        else:
            if os.path.isfile(path):
                return self._copy_file(path)
            else:
                logger.debug("File %s does not exist", path)
                return False
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;
    }
721424
public function copy($path, $newpath)
    {
        list (, $srcId) = $this->splitPath($path);

        list ($newParentId, $fileName) = $this->splitPath($newpath);

        $file = new Google_Service_Drive_DriveFile();
        $file->setName($fileName);
        $file->setParents([
            $newParentId
        ]);

        $newFile = $this->service->files->copy($srcId, $file, $this->applyDefaultParams([
            'fields' => $this->fetchfieldsGet
        ], 'files.copy'));

        if ($newFile instanceof Google_Service_Drive_DriveFile) {
            $this->cacheFileObjects[$newFile->getId()] = $newFile;
            $this->cacheFileObjectsByName[$newParentId . '/' . $fileName] = $newFile;
            list ($newDir) = $this->splitPath($newpath);
            $newpath = (($newDir === $this->root) ? '' : ($newDir . '/')) . $newFile->getId();
            if ($this->getRawVisibility($path) === AdapterInterface::VISIBILITY_PUBLIC) {
                $this->publish($newpath);
            } else {
                $this->unPublish($newpath);
            }
            return true;
        }

        return false;
    }
1084116
def file_tree(start_path):
    
    nested_dirs = {}
    root_dir = start_path.rstrip(os.sep)
    start = root_dir.rfind(os.sep) + 1
    for path, dirs, files in os.walk(root_dir):
        folders = path[start:].split(os.sep)
        subdir = dict.fromkeys(files)
        parent = reduce(dict.get, folders[:-1], nested_dirs)
        parent[folders[-1]] = subdir
    return nested_dirs
365683
public function copy($path, $newpath)
    {
        $object = $this->applyPathPrefix($path);
        $newobject = $this->applyPathPrefix($newpath);

        try {
            $this->client->copyObject($this->bucket, $object, $this->bucket, $newobject);
        } catch (OssException $e) {
            return false;
        }

        return true;
    }