import { exists } from "https://deno.land/x/ayonli_jsext@v0.9.72/esm/fs.js";
Checks if the given path exists.
This function may throw an error if the path is invalid or the operation is not allowed.
NOTE: This function can also be used in Cloudflare Workers.
Examples
Example 1
Example 1
// with the default storage
import { exists } from "@ayonli/jsext/fs";
if (await exists("/path/to/file.txt")) {
console.log("The file exists.");
} else {
console.log("The file does not exist.");
}
Example 2
Example 2
// with a user-selected directory as root (Chromium only)
import { exists } from "@ayonli/jsext/fs";
const root = await window.showDirectoryPicker();
if (await exists("/path/to/file.txt", { root })) {
console.log("The file exists.");
} else {
console.log("The file does not exist.");
}