Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/fs/mod.ts>copy

The Deno Standard Library
Latest
The Standard Library has been moved to JSR. See the blog post for details.
function copy
import { copy } from "https://deno.land/std@0.224.0/fs/mod.ts";

Asynchronously copy a file or directory. The directory can have contents. Like cp -r.

If src is a directory it will copy everything inside of this directory, not the entire directory itself. If src is a file, dest cannot be a directory.

Requires the --allow-read and --allow-write flag.

Examples

Basic usage

import { copy } from "https://deno.land/std@0.224.0/fs/copy.ts";

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

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

Overwriting files/directories

import { copy } from "https://deno.land/std@0.224.0/fs/copy.ts";

await copy("./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 { copy } from "https://deno.land/std@0.224.0/fs/copy.ts";

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.

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 = [UNSUPPORTED]

Options for copying.