Skip to content

rm ​

Removes a file or directory. For directories, use { recursive: true } to remove all contents.

Signaturerm(path: string, options?: RmOptions): Result<void, FsError>

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

Options ​

RmOptions is an interface with two optional fields:

  • recursive?: boolean, when true, removes directories and all their contents recursively. Defaults to false.
  • force?: boolean, when true, silently ignores non-existent paths. Defaults to false.

Example ​

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

match (rm("temp.txt")) {
    Ok(_) => {}
    Err(error) => { printError(error.code); // ERR_FS_RM_FAILED
    }
}
match (rm("subdir", { recursive: true, force: true })) {
    Ok(_) => {}
    Err(error) => { printError(error.code); // ERR_FS_RM_FAILED
    }
}