copy

import { copy } from "jsr:@ende/fs";

function

async function copy(src: string | URL, dest: string | URL, options: CopyOptions = [UNSUPPORTED]): Promise<void>

Asynchronously copy a file or directory (along with its contents), like cp -r.

Both src and dest must both be a file or directory.

Requires --allow-read and --allow-write permissions.

src: string | URL

The source file/directory path as a string or URL.

dest: string | URL

The destination file/directory path as a string or URL.

options: CopyOptions = [UNSUPPORTED]

Options for copying.

Returns

A promise that resolves once the copy operation completes.

Example: Basic usage

import { copy } from "@ende/fs/copy";

await copy("./foo", "./bar");

This will copy the file or directory at ./foo to ./bar without overwriting.

Example: Overwriting files/directories

import { copy } from "@ende/fs/copy";

await copy("./foo", "./bar", { overwrite: true });

This will copy the file or directory at ./foo to ./bar and overwrite any existing files or directories.

Example: Preserving timestamps

import { copy } from "@ende/fs/copy";

await copy("./foo", "./bar", { preserveTimestamps: true });

This will copy the file or directory at ./foo to ./bar and set the last modification and access times to the ones of the original source files.

See also

Source