Copy folder to new directory path.

@param string $newDirectoryPath New directory path

@return Folder

@throws FolderException
191339
public function copyToDirectory(string $newDirectoryPath): self
    {
        $newDirectoryPath = normalize_path($newDirectoryPath);

        if (is_dir($newDirectoryPath)) {
            if (is_writeable($newDirectoryPath)) {
                $newFolderPath = $newDirectoryPath.DIRECTORY_SEPARATOR.$this->getName();
                $this->copy($newFolderPath);
            }
            throw new FolderException('Cannot copy the folder, because the new directory path ('.$newDirectoryPath.') is not writable',
                FolderException::NOT_WRITEABLE);
        }
        throw new FolderException('Cannot copy the folder, because the new directory path ('.$newDirectoryPath.') does not exist',
            FolderException::DONT_EXIST);
    }
585031
private function copyDir(Response $response, $target, $dst, $newFolder = '')
    {
        $folder = trim(strrchr($target, DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR);
        $newFolder = $newFolder ?: $dst.DIRECTORY_SEPARATOR.$folder;
        if (file_exists($newFolder)) {
            throw new ExistsException(sprintf('folder "%s" exists', $newFolder));
        }
        mkdir($newFolder);
        $response->addAdded($this->getFileInfo($newFolder));
        foreach (glob($target.'/*') as $name) {
            if (is_dir($name)) {
                $this->copyDir($response, $name, $newFolder);
            } else {
                $filename = $newFolder.DIRECTORY_SEPARATOR.$this->basename($name);
                copy($name, $filename);
                $response->addAdded($this->getFileInfo($filename));
            }
        }
    }
1298916
public function createDirectory($dirPath)
    {
      if (! $this->fs->exists($dirPath))
      {
        $this->fs->mkdir($dirPath);
      }
    }
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);
    }
1257720
public function setRootDir($rootPath = false)
    {
        if (!$rootPath) {
            $this->rootDir = getcwd().DS;
        }

        $this->rootDir = $rootPath.DS;

        return $this;
    }
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);
        }
    }
180127
public function makeDirectory($path)
    {
        if ($this->files->isDirectory($path) === false) {
            $this->files->makeDirectory($path, 0777, true, true);
        }

        return $this;
    }
120034
public static function createFolder($path)
    {
        $path = self::resolve($path);

        return $path && (is_dir($path) || mkdir($path, 0700, true));
    }
714984
public function directory($path)
    {
        if (!File::exists($path)) {
            File::makeDirectory($path, 0775, true, true);
        }
        return $this;
    }
257673
public function setDirectory($path) {
        if (substr($path, -1) !== '/') {
            $path .= '/';
        }

        if (!file_exists($path)) {
            mkdir($path, 0777, true);

        } else if (!is_writable($path)) {
            chmod($path, 0777);
        }

        $this->_directory = $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);
    }
424595
public function copy($path, $toPath)
    {
        if (empty($path) || empty($toPath)) return false;

        return copy($path, $toPath);
    }
354177
protected function createFolder($folderPath)
    {
        if(!@mkdir($folderPath,0777,true) && !is_dir($folderPath))
        {
            throw new FileSystemException(
                new Phrase('Folder can not be created, but does not exist.')
            );
        }     
        
        return $this;
    }
124804
public function copy($path, $newpath)
    {
        return (bool) $this->normalizeResponse(
            $this->cosApi->copyFile($this->getBucket(), $path, $newpath, true)
        );
    }
569031
public function addDirectory($path)
    {
        $finder = new Finder();
        $finder->files()
            ->ignoreVCS(true)
            ->name('*.php')
            ->in($path);

        foreach ($finder as $file) {
            $this->addFile($file);
        }

        return $this;
    }
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;
    }
593317
public function moveFolder($originalPath, $newPath)
    {
        if (Str::lower($originalPath) !== Str::lower($newPath)) {
            // If there is no risk that the directory was renamed
            // by just changing the letter case in the name -
            // copy the directory to the destination path and delete
            // the source directory.

            if (!$this->copyFolder($originalPath, $newPath)) {
                return false;
            }

            $this->deleteFolder($originalPath);
        }
        else {
            // If there's a risk that the directory name was updated
            // by changing the letter case - swap source and destination
            // using a temporary directory with random name.

            $tempraryDirPath = $this->generateRandomTmpFolderName(dirname($originalPath));

            if (!$this->copyFolder($originalPath, $tempraryDirPath)) {
                $this->deleteFolder($tempraryDirPath);

                return false;
            }

            $this->deleteFolder($originalPath);

            return $this->moveFolder($tempraryDirPath, $newPath);
        }

        return true;
    }