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

Function emptyDir

fs/empty_dir.ts:27–45  ·  view source on GitHub ↗
(dir: string | URL)

Source from the content-addressed store, hash-verified

25 * ```
26 */
27export async function emptyDir(dir: string | URL) {
28 try {
29 const items = await Array.fromAsync(Deno.readDir(dir));
30
31 await Promise.all(items.map((item) => {
32 if (item && item.name) {
33 const filepath = join(toPathString(dir), item.name);
34 return Deno.remove(filepath, { recursive: true });
35 }
36 }));
37 } catch (err) {
38 if (!(err instanceof Deno.errors.NotFound)) {
39 throw err;
40 }
41
42 // if not exist. then create it
43 await Deno.mkdir(dir, { recursive: true });
44 }
45}
46
47/**
48 * Synchronously ensures that a directory is empty deletes the directory

Callers 2

empty_dir_test.tsFile · 0.90
empty_dir.tsFile · 0.90

Calls 3

joinFunction · 0.90
toPathStringFunction · 0.90
removeMethod · 0.45

Tested by

no test coverage detected