Skip to content

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.

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

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

Observaçõ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);
        }
    }
};