Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

std/fs/mod.ts>copySync

The Deno Standard Library
Go to Latest
function copySync
import { copySync } from "https://deno.land/std@0.223.0/fs/mod.ts";

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

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

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

Overwriting files/directories

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

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 "https://deno.land/std@0.223.0/fs/copy.ts";

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

Options for copying.