public function copyPath($from, $to, $replace = true, $purge = true)
    {
        if (false === file_exists($from)) {
            throw FileSystemException::invalidPath($from);
        }

        if (is_dir($from)) {
            if (false === file_exists($to)) {
                if (false === @ mkdir($to)) {
                    throw FileSystemException::lastError(
                        $to,
                        "The directory \"$to\" could not be created: "
                    );
                }
            }

            if (false === ($dh = @ opendir($from))) {
                throw FileSystemException::lastError(
                    $to,
                    "The directory \"$from\" could not be opened: "
                );
            }

            while (false !== ($item = readdir($dh))) {
                if (('.' === $item) || ('..' === $item)) {
                    continue;
                }

                $this->copyPath(
                    $from . DIRECTORY_SEPARATOR . $item,
                    $to . DIRECTORY_SEPARATOR . $item,
                    $replace,
                    false
                );
            }

            closedir($dh);
        } elseif (false === (file_exists($to) && (false === $replace))) {
            if (false === @ copy($from, $to)) {
                throw FileSystemException::lastError($to);
            }
        }

        if ($purge) {
            $this->purgePaths[] = $to;
        }
    }
public function copyPath($from, $to, $replace = true, $purge = true)
    {
        if (false === file_exists($from)) {
            throw FileSystemException::invalidPath($from);
        }

        if (is_dir($from)) {
            if (false === file_exists($to)) {
                if (false === @ mkdir($to)) {
                    throw FileSystemException::lastError(
                        $to,
                        "The directory \"$to\" could not be created: "
                    );
                }
            }

            if (false === ($dh = @ opendir($from))) {
                throw FileSystemException::lastError(
                    $to,
                    "The directory \"$from\" could not be opened: "
                );
            }

            while (false !== ($item = readdir($dh))) {
                if (('.' === $item) || ('..' === $item)) {
                    continue;
                }

                $this->copyPath(
                    $from . DIRECTORY_SEPARATOR . $item,
                    $to . DIRECTORY_SEPARATOR . $item,
                    $replace,
                    false
                );
            }

            closedir($dh);
        } elseif (false === (file_exists($to) && (false === $replace))) {
            if (false === @ copy($from, $to)) {
                throw FileSystemException::lastError($to);
            }
        }

        if ($purge) {
            $this->purgePaths[] = $to;
        }
    }
public function copyPath ( $ from , $ to , $ replace = true , $ purge = true ) { if ( false === file_exists ( $ from ) ) { throw FileSystemException :: invalidPath ( $ from ) ; } if ( is_dir ( $ from ) ) { if ( false === file_exists ( $ to ) ) { if ( false === @ mkdir ( $ to ) ) { throw FileSystemException :: lastError ( $ to , "The directory \"$to\" could not be created: " ) ; } } if ( false === ( $ dh = @ opendir ( $ from ) ) ) { throw FileSystemException :: lastError ( $ to , "The directory \"$from\" could not be opened: " ) ; } while ( false !== ( $ item = readdir ( $ dh ) ) ) { if ( ( '.' === $ item ) || ( '..' === $ item ) ) { continue ; } $ this -> copyPath ( $ from . DIRECTORY_SEPARATOR . $ item , $ to . DIRECTORY_SEPARATOR . $ item , $ replace , false ) ; } closedir ( $ dh ) ; } elseif ( false === ( file_exists ( $ to ) && ( false === $ replace ) ) ) { if ( false === @ copy ( $ from , $ to ) ) { throw FileSystemException :: lastError ( $ to ) ; } } if ( $ purge ) { $ this -> purgePaths [ ] = $ to ; } }
Recursively copies a file or directory tree to another location.

@param string  $from    The source file system path.
@param string  $to      The target file system path.
@param boolean $replace Replacing existing files?
@param boolean $purge   Automatically purge?

@throws FileSystemException If the path could not be copied.
Recursively copies a file or directory tree to another location .