public function copyDirectory(string $source, string $target, int $flags = null) : bool
    {
        if (!$this->exists($source)) {
            return false;
        }

        if (!$this->isDirectory($target) && !$this->makeDirectory($target, 0777, true)) {
            return false;
        }

        if ($flags === null) {
            $flags = FilesystemIterator::SKIP_DOTS;
        }

        $items = new FilesystemIterator($source, $flags);

        foreach ($items as $item) {
            if ($item->isDir()) {
                if (!$this->copyDirectory($item->getRealPath(), $target . '/' . $item->getBasename(), $flags)) {
                    return false;
                }
            } elseif ($item->isFile()) {
                if (!$this->copyFile($item->getRealPath(), $target . '/' . $item->getBasename())) {
                    return false;
                }
            }
        }

        return true;
    }
public function copyDirectory(string $source, string $target, int $flags = null) : bool
    {
        if (!$this->exists($source)) {
            return false;
        }

        if (!$this->isDirectory($target) && !$this->makeDirectory($target, 0777, true)) {
            return false;
        }

        if ($flags === null) {
            $flags = FilesystemIterator::SKIP_DOTS;
        }

        $items = new FilesystemIterator($source, $flags);

        foreach ($items as $item) {
            if ($item->isDir()) {
                if (!$this->copyDirectory($item->getRealPath(), $target . '/' . $item->getBasename(), $flags)) {
                    return false;
                }
            } elseif ($item->isFile()) {
                if (!$this->copyFile($item->getRealPath(), $target . '/' . $item->getBasename())) {
                    return false;
                }
            }
        }

        return true;
    }
public function copyDirectory ( string $ source , string $ target , int $ flags = null ) : bool { if ( ! $ this -> exists ( $ source ) ) { return false ; } if ( ! $ this -> isDirectory ( $ target ) && ! $ this -> makeDirectory ( $ target , 0777 , true ) ) { return false ; } if ( $ flags === null ) { $ flags = FilesystemIterator :: SKIP_DOTS ; } $ items = new FilesystemIterator ( $ source , $ flags ) ; foreach ( $ items as $ item ) { if ( $ item -> isDir ( ) ) { if ( ! $ this -> copyDirectory ( $ item -> getRealPath ( ) , $ target . '/' . $ item -> getBasename ( ) , $ flags ) ) { return false ; } } elseif ( $ item -> isFile ( ) ) { if ( ! $ this -> copyFile ( $ item -> getRealPath ( ) , $ target . '/' . $ item -> getBasename ( ) ) ) { return false ; } } } return true ; }
Copies directories to a new path

@param string $source The path to copy from
@param string $target The path to copy to
@param null|int $flags The file permissions to use for the new directory(ies)
@return bool True if successful, otherwise false
Copies directories to a new path