Copy folder content (sub files and sub folders) to new folder path.

@param string $newFolderPath New folder path

@return Folder

@throws FolderException
160720
public function copyContent(string $newFolderPath): self
    {
        $newFolderPath = normalize_path($newFolderPath);

        if (is_dir($newFolderPath)) {
            if (recursive_copy($this->getPath(), $newFolderPath)) {
                return self::load($newFolderPath);
            }
        }
        throw new FolderException('Cannot copy folder content, because the destination folder path ('.$newFolderPath.') does not exist',
            FolderException::DONT_EXIST);
    }
671341
public function copy($path, $newpath)
    {
        $url = cloudinary_url_internal($path);
        $result = Uploader::upload($url, ['public_id' => $newpath]);

        return is_array($result) ? $result['public_id'] == $newpath : false;
    }
1115557
public static function createFromFilePath ($filePath)
    {
        if (!is_file($filePath))
        {
            throw new \InvalidArgumentException("File does not exist");
        }
        else if (!is_readable($filePath))
        {
            throw new \InvalidArgumentException("File to download is not readable.");
        }

        return new FileDownload(fopen($filePath, "rb"));
    }
307395
public function addFolder(string $path): self
    {
        Arr::unShift($this->folders, $path);

        return $this;
    }
313113
public function copy($newPath = null)
    {
        if (is_null($newPath)) {
            $newPath = $this->path . '-copy';
        }

        if (@$this->filesystem->copy($this->path, $newPath)) {
            return $this->getClone()->setPath($newPath);
        } else {
            $lastError = error_get_last();
            throw new CopyFailedException($this, $newPath, $lastError['message']);
        }
    }
1107996
public function rename($oldPath, $newPath)
    {
        $old = $this->at($oldPath);
        $new = $this->at($newPath);

        if (null === $old || (null !== $new && 'dir' === $new->type))
            return false;

        if ('file' === $old->type) {
            $this->at($newPath, $old);
        } else {
            if (! $this->mkdir($newPath, $old->perms)) {
                return false;
            }
            $oldPath = $this->realpath($oldPath) . '/';
            $newPath = $this->realpath($newPath) . '/';
            $length = strlen($oldPath);
            foreach (array_keys($this->files) as $childPath) {
                if (substr($childPath, 0, $length) === $oldPath) {
                    $newChildPath = $newPath . substr($childPath, $length);
                    $this->at($newChildPath, $this->at($childPath));
                    $this->at($childPath, null);
                }
            }
        }
        $this->at($oldPath, null);
        return true;
    }
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;

    }
262083
public function copyDirectory($sourcePath, $destinationPath)
    {
        $sourceDirectory = opendir($sourcePath);

        if (! is_dir($destinationPath)) {
            self::createDirectory($destinationPath);
        }
        while (false !== ($file = readdir($sourceDirectory))) {
            if (($file !== '.') && ($file !== '..')) {
                $sourceFile = $sourcePath.'/'.$file;
                $destinationFile = $destinationPath.'/'.$file;
                if (is_dir($sourceFile)) {
                    self::copyDirectory($sourceFile, $destinationFile);
                } else {
                    self::copyFile($sourceFile, $destinationFile);
                }
            }
        }
        closedir($sourceDirectory);
    }
1373354
public function getFolder($path = '')
    {
        if (!array_key_exists($path,$this->folders)) {

            $this->folders[$path] = false;
            if (file_exists($this->baseFolder . '/' . $path)) {
                $result = ['folders' => $this->listSubFolder($path), 'files' => $this->listFiles($path)];

                $folder = new Folder($path, $result);

                $this->folders[$path] = $folder;

            }
        }

        return $this->folders[$path];

    }
305532
public function setFilePath($path) {
		$path = realpath($path);
		
		if ($path === false) {
			throw new NoPath('Invalid path: ' . $path);
		}
		
		$this->path = $path;
		
		return $this;
	}
379594
protected function _folder($oldPath, $newPath) {
        if (!is_dir($newPath)) {
            $oldumask = umask(0);
            mkdir($newPath, 01777); // so you get the sticky bit set 
            umask($oldumask);
        } elseif (filemtime($oldPath) < filemtime($newPath)) {
            //$this->debug($oldPath . ': ' . filemtime($oldPath). ' < ' . filemtime($newPath));
            return;
        } else {
            //$this->debug($oldPath . ': ' . filemtime($oldPath). ' > ' . filemtime($newPath));
        }
        $dir = @opendir($oldPath) or trigger_error("Unable to open original folder to copy it! ($oldPath)");
        while ($file = readdir($dir)) {
            if ($file != "." && $file != ".." && !is_dir("$oldPath/$file")) {
                copy("$oldPath/$file", "$newPath/$file");
            } elseif ($file != "." && $file != "..") {
                $this->_folder("$oldPath/$file", "$newPath/$file");
            }
        }
        closedir($dir);
    }
1002590
protected function newPath(/*# string */ $path)/*# : Path */
    {
        list($mnt, $remain) = $this->splitPath($path);
        return new Path($path, $remain, $this->getFilesystemAt($mnt));
    }
775291
public function setFilePath( $filePath )
	{
		$this->filePath      = $filePath;
		$this->shortFilePath = str_replace( base_path() , '' , $filePath );

		return $this;
	}
552235
public function copy(string $fromPath, string $toPath): array
    {
        $parameters = [
            'from_path' => $this->normalizePath($fromPath),
            'to_path' => $this->normalizePath($toPath),
        ];

        return $this->rpcEndpointRequest('files/copy_v2', $parameters);
    }
1105376
public function rename($oldPath, $newPath)
    {
        $payload = $this->getNewFileLocationPayload($newPath);

        return $this->updateMetadata($oldPath, $payload);
    }
732051
private static function compareContents($filePath, $newContent)
    {
        if (file_exists($filePath)) {
            $currentContent = file_get_contents($filePath);
            return strcmp($currentContent, $newContent) === 0;
        }

        return false;
    }
1222591
public function rename($newpath)
    {
        if ($this->filesystem->rename($this->path, $newpath)) {
            $this->path = $newpath;

            return true;
        }

        return false;
    }