(dir: string | URL)
| 25 | * ``` |
| 26 | */ |
| 27 | export 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 |
no test coverage detected