Skip to content

Path.copy() method

pathlib-ts > Path > copy

Recursively copy this file or directory tree to the destination.

Signature:

copy(target: PathLike, options?: {
preserveMetadata?: boolean;
followSymlinks?: boolean;
}): Promise<Path>;

Parameter

Type

Description

target

PathLike

Destination path or string.

options

{ preserveMetadata?: boolean; followSymlinks?: boolean; }

(Optional) Behaviour flags for metadata preservation and symlink handling.

Returns:

Promise<Path>

Promise resolving to the destination Path.

Uses Node’s fs.cp to match CPython’s recursive behavior while exposing options for metadata and symlink handling.

Publishing build output asynchronously

import { Path } from "pathlib-ts";
const build = new Path("./build");
const publicDir = new Path("./public");
await build.copy(publicDir, { preserveMetadata: true });