Skip to content

cp ​

Copies a file or directory from src to dest. For directories, use { recursive: true }.

Signaturecp(src: string, dest: string, options?: CpOptions): Result<void, FsError>

The operation returns Err(FsError) on failure; inspect it with match or propagate it with ?.

Options ​

CpOptions is an interface with two optional fields:

  • recursive?: boolean, when true, copies directories recursively. Required for directory sources. Defaults to false.
  • force?: boolean, when true, overwrites existing files at the destination. Defaults to false.

Example ​

tyrus
import { cp, type FsError } from "tyrus:fs";

match (cp("source.txt", "dest.txt")) {
    Ok(_) => {}
    Err(error) => { printError(error.code); // ERR_FS_CP_FAILED
    }
}