exists
exists verifica se um caminho existe no sistema de arquivos e retorna um boolean. exists retorna false para qualquer erro (arquivo inexistente, permissão negada etc.) em vez de retornar um Result.
Assinatura
exists(path: string): booleantyrus
import { exists } from "tyrus:fs";
const ok: boolean = exists("README.md");
print(ok); // trueObservações
exists é uma verificação conveniente para quem precisa apenas saber se um caminho está acessível. As outras operações recuperáveis retornam Result e devem ser tratadas com match ou ?:
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);
}
}
};