Skip to main content
Module

x/johnny_decimal/deps.ts>exists

Utilities for interacting with a Johnny Decimal filing system.
Latest
function exists
Re-export
import { exists } from "https://deno.land/x/johnny_decimal@1.2.0/deps.ts";

Test whether or not the given path exists by checking with the file system. Please consider to check if the path is readable and either a file or a directory by providing additional options:

import { exists } from "https://deno.land/std@0.223.0/fs/mod.ts";
const isReadableDir = await exists("./foo", {
  isReadable: true,
  isDirectory: true
});
const isReadableFile = await exists("./bar", {
  isReadable: true,
  isFile: true
});

Note: Do not use this function if performing a check before another operation on that file. Doing so creates a race condition. Instead, perform the actual file operation directly.

Bad:

import { exists } from "https://deno.land/std@0.223.0/fs/mod.ts";

if (await exists("./foo")) {
  await Deno.remove("./foo");
}

Good:

// Notice no use of exists
try {
  await Deno.remove("./foo", { recursive: true });
} catch (error) {
  if (!(error instanceof Deno.errors.NotFound)) {
    throw error;
  }
  // Do nothing...
}

Parameters

path: string | URL
optional
options: ExistsOptions

Returns

Promise<boolean>