复制目录

@param string $source 要复制的目录地址
@param string $destination 目标目录地址
@param int $child 是否复制子目录
@return bool
358141
public static function xCopy($source, $destination, $child = 1)
    {
        if (!is_dir($source)) {
            echo("Error:the $source is not a direction!");
            return 0;
        }
        if (!is_dir($destination)) {
            mkdir($destination, 0777);
        }
        $handle = dir($source);
        while ($entry = $handle->read()) {
            if (($entry != ".") && ($entry != "..")) {
                if (is_dir($source . "/" . $entry)) {
                    if ($child) self::xCopy($source . "/" . $entry, $destination . "/" . $entry, $child);
                } else {
                    copy($source . "/" . $entry, $destination . "/" . $entry);
                }
            }
        }
        return 1;
    }
977413
public static function map( $source, $destination, iterable $map ) {

    // sanity check
    if( !static::is( $source, false, true ) ) throw new \TypeError( 'The $source must be arraylike' );
    else if( !static::is( $destination, false, true ) ) throw new \TypeError( 'The $destination must be arraylike' );
    else {

      // iterate $map and fill the destination based on it
      foreach( $map as $key => $key_list ) {

        $value    = $source[ Number::is( $key ) ? $key_list : $key ] ?? null;
        $key_list = static::cast( $key_list, [ $key_list ] );
        foreach( $key_list as $_key ) {
          $destination[ $_key ] = $value;
        }
      }

      return $destination;
    }
  }
672234
public function copyr($source, $dest)
    {
        // Simple copy for a file
        if (is_file($source)) {
            return $this->copy($source, $dest);
        }
        // Make destination directory
        if (!is_dir($dest)) {
            $this->mkdir($dest);
        }
        // Loop through the folder
        $dir = $this->dir($source);
        while ( false !== ($entry = $dir->read()) ) {
            // Skip pointers
            if ($entry == '.' || $entry == '..') {
                continue;
            }
            if (!$this->copyable($entry)) {
                continue;
            }
            // Deep copy directories
            if ($dest !== "$source/$entry") {
                $this->copyr("$source/$entry", "$dest/$entry");
            }
        }
        // Clean up
        $dir->close();
        return true;
    }
1007520
public static boolean copy(File source, File destination) {
        boolean result = true;
        if (source.isDirectory()) {
            if (destination.exists()) {
                result = result && destination.isDirectory();
            } else {
                result = result && destination.mkdirs();
            }
            File[] children = source.listFiles();
            for (File element : children) {
                result =
                        result
                                && copy(new File(source, element.getName()),
                                        new File(destination, element.getName()));
            }
            return result;
        } else {
            try {
                InputStream in = new FileInputStream(source);
                OutputStream out = new FileOutputStream(destination);
                result = result && copy(in, out);
                in.close();
                out.close();
                return result;
            } catch (IOException e) {
                return false;
            }
        }
    }
476787
private function createProjectFile(string $source, string $destination)
    {
        try{
            $this->createFileFromTemplate ([
                "destination"         => $destination,
                "templateDestination" => __DIR__ . '/templates/project/' . $source
            ]);
        } catch (Exception $e)
        {
        }
    }
779560
public function copyFile($source, $target, $file)
    {
        $this->mkDir($target);
        if (file_exists($source.$file)) {
            copy($source.$file, $target.$file);
        }
    }
1337156
private function link(string $source, string $target): bool
    {
        if (!@link($source, $target)) {
            $message = 'Could not create link.';
            if ($error = error_get_last()) {
                $message .= sprintf(' Errno: %d; %s', $error['type'], $error['message']);
            }
            throw new FileException($message);
        }

        return true;
    }
158175
private function copyRecursive($source, $target)
    {
        if (!is_dir($source)) {
            $this->filesystem->ensureDirectoryExists(dirname($target));
            copy($source, $target);

            return;
        }

        $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),
            \RecursiveIteratorIterator::SELF_FIRST
        );

        $this->filesystem->ensureDirectoryExists($target);

        foreach ($iterator as $file) {
            $targetPath = $target . DIRECTORY_SEPARATOR . $iterator->getSubPathName();
            if ($file->isDir()) {
                $this->filesystem->ensureDirectoryExists($targetPath);
            } else {
                copy($file->getPathname(), $targetPath);
            }
        }
    }
1100751
public function extract($file, $source, $destination)
    {
        $this->_setCurrentFile($source);
        $this->_initReader();

        $archiveReader = $this->_getReader();
        $extractedFile = '';

        while (!$archiveReader->eof()) {
            $header = $this->_extractFileHeader();
            if ($header['name'] == $file) {
                $extractedFile = $destination . basename($header['name']);
                $this->_extractAndWriteFile($header, $extractedFile);
                break;
            }

            if ($header['type'] != 5){
                $skipBytes = floor(($header['size'] + self::TAR_BLOCK_SIZE - 1) / self::TAR_BLOCK_SIZE)
                    * self::TAR_BLOCK_SIZE;
                $archiveReader->read($skipBytes);
            }
        }

        $this->_destroyReader();
        return $extractedFile;
    }
720221
public function connect(string $source, string $destination): void
    {
        $outNode = $this->nodes[$source];
        $inNode = $this->nodes[$destination];

        $edge = new DocumentGraphEdge($outNode, $inNode);

        $outNode->addOutEdge($edge);
        $inNode->addInEdge($edge);
    }
458873
public function copy($source, $destination = null)
    {
        if ($destination === null) {
            $destination = basename($source);
        }

        $this->toCopy[] = array($source, $destination);

        return $this;
    }
787774
static function copyFile($source, $target, $overwrite = true)
    {
        if (!file_exists($source)) return false;
        if (file_exists($target) && $overwrite == false) return false;
        elseif (file_exists($target) && $overwrite == true) {
            if (!unlink($target)) return false;
        }
        $targetDir = dirname($target);
        if (!self::createDirectory($targetDir)) return false;
        return copy($source, $target);
    }
960885
protected function copyNode(INode $source, ICollection $destinationParent, $destinationName = null)
    {
        if ('' === (string) $destinationName) {
            $destinationName = $source->getName();
        }

        if ($source instanceof IFile) {
            $data = $source->get();

            // If the body was a string, we need to convert it to a stream
            if (is_string($data)) {
                $stream = fopen('php://temp', 'r+');
                fwrite($stream, $data);
                rewind($stream);
                $data = $stream;
            }
            $destinationParent->createFile($destinationName, $data);
            $destination = $destinationParent->getChild($destinationName);
        } elseif ($source instanceof ICollection) {
            $destinationParent->createDirectory($destinationName);

            $destination = $destinationParent->getChild($destinationName);
            foreach ($source->getChildren() as $child) {
                $this->copyNode($child, $destination);
            }
        }
        if ($source instanceof IProperties && $destination instanceof IProperties) {
            $props = $source->getProperties([]);
            $propPatch = new PropPatch($props);
            $destination->propPatch($propPatch);
            $propPatch->commit();
        }
    }
77725
private function copyFile(
        FilesystemInterface $source,
        FilesystemInterface $destination,
        $path
    ) {
        $destination->put(
            $path,
            $source->read($path)
        );
    }
177825
public static function copyRecursive($source, $destination)
    {
        if (is_dir($source)) {
            $dir_handle = opendir($source);

            while ($file = readdir($dir_handle)) {
                if ($file != "." && $file != "..") {
                    self::mkDir($destination);

                    if (is_dir($source . "/" . $file)) {
                        if (!is_dir($destination . "/" . $file)) {
                            mkdir($destination . "/" . $file);
                        }
                        self::copyRecursive($source . "/" . $file, $destination . "/" . $file);
                    } else {
                        copy($source . "/" . $file, $destination . "/" . $file);
                    }
                }
            }
            closedir($dir_handle);
        } else {
            copy($source, $destination);
        }

        return true;
    }
87495
public static boolean isUnderDirectory(File child, File parent) {
        if (child == null || parent == null)
            return false;

        URI childUri = child.toURI();
        URI relativeUri = parent.toURI().relativize(childUri);
        return relativeUri.equals(childUri) ? false : true;

    }
776418
public function pack($source, $destination, $skipRoot = false)
    {
        $this->_setSkipRoot($skipRoot);
        $source = realpath($source);
        $tarData = $this->_setCurrentPath($source)
            ->_setDestinationFilePath($destination)
            ->_setCurrentFile($source);

        $this->_initWriter();
        $this->_createTar($skipRoot, true);
        $this->_destroyWriter();

        return $destination;
    }