MCPcopy Create free account
hub / github.com/denoland/std / remove

Function remove

fs/unstable_remove.ts:32–54  ·  view source on GitHub ↗
(
  path: string | URL,
  options?: RemoveOptions,
)

Source from the content-addressed store, hash-verified

30 * @param options Options when reading a file. See {@linkcode RemoveOptions}.
31 */
32export async function remove(
33 path: string | URL,
34 options?: RemoveOptions,
35) {
36 if (isDeno) {
37 await Deno.remove(path, options);
38 } else {
39 const { recursive = false } = options ?? {};
40 try {
41 await getNodeFs().promises.rm(path, { recursive: recursive });
42 } catch (error) {
43 if ((error as Error & { code: string }).code === "ERR_FS_EISDIR") {
44 try {
45 await getNodeFs().promises.rmdir(path);
46 } catch (error) {
47 throw mapError(error);
48 }
49 return;
50 }
51 throw mapError(error);
52 }
53 }
54}
55
56/**
57 * Synchronously removes the named file or directory.

Calls 3

getNodeFsFunction · 0.90
mapErrorFunction · 0.90
removeMethod · 0.45

Tested by

no test coverage detected