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.
Signature
exists(path: string): booleantyrus
import { exists } from "tyrus:fs";
const ok: boolean = exists("README.md");
print(ok); // trueNotes
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);
}
}
};