1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/fs/ensure_dir.ts

30 lines
726 B
TypeScript
Raw Normal View History

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
/**
* Ensures that the directory exists.
* If the directory structure does not exist, it is created. Like mkdir -p.
*/
export async function ensureDir(dir: string): Promise<void> {
try {
// if dir exists
await Deno.stat(dir);
} catch {
// if dir not exists. then create it.
await Deno.mkdir(dir, true);
}
}
/**
* Ensures that the directory exists.
* If the directory structure does not exist, it is created. Like mkdir -p.
*/
export function ensureDirSync(dir: string): void {
try {
// if dir exists
Deno.statSync(dir);
} catch {
// if dir not exists. then create it.
Deno.mkdirSync(dir, true);
}
}