Skip to main content

@std/fs@1.0.6
Built and signed on GitHub Actions

Helpers for working with the file system

This package works with Deno
This package works with Deno
JSR Score
94%
Published
5 days ago (1.0.6)
function copySync
copySync(
src: string | URL,
dest: string | URL,
options?: CopyOptions,
): void

Synchronously 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.

Examples

Basic usage

import { copySync } from "@std/fs/copy";

copySync("./foo", "./bar");

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

Overwriting files/directories

import { copySync } from "@std/fs/copy";

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

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

Preserving timestamps

import { copySync } from "@std/fs/copy";

copySync("./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.

Parameters

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.

optional
options: CopyOptions

Options for copying.

Return Type

void

A void value that returns once the copy operation completes.

See

Add Package

deno add jsr:@std/fs

Import symbol

import { copySync } from "@std/fs/copy";

---- OR ----

Import directly with a jsr specifier

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