rm
Removes a file or directory. For directories, use { recursive: true } to remove all contents.
Signature
rm(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, whentrue, removes directories and all their contents recursively. Defaults tofalse.force?: boolean, whentrue, silently ignores non-existent paths. Defaults tofalse.
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
}
}