Skip to content

exists ​

exists checks whether a path exists on the filesystem and returns a boolean. exists returns false for any error (missing file, permission denied, etc.) instead of returning a Result.

Signatureexists(path: string): boolean
tyrus
import { exists } from "tyrus:fs";

const ok: boolean = exists("README.md");
print(ok); // true

Notes ​

exists is a convenience check for callers that only need to know whether a path is accessible. Other recoverable operations return Result and should be handled with match or ?:

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

const main = (): void => {
    const path: string = "config.json";
    if (exists(path)) {
        match (readFileSync(path)) {
            Ok(config) => print(config);
            Err(error) => printError(error.message);
        }
    }
};