Last active
May 28, 2018 21:58
-
-
Save MurhafSousli/6a72ac2c4e0fc940ce327e20b9378775 to your computer and use it in GitHub Desktop.
Create directory recursively for a giving path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { existsSync, mkdirSync } from 'fs'; | |
import { dirname } from 'path'; | |
function makeDirectory(target: string) { | |
// check if parent directory exists | |
const parentDir = dirname(target); | |
if (!existsSync(parentDir)) { | |
makeDirectory(parentDir); | |
} | |
// check if directory exists | |
if (!existsSync(target)) { | |
mkdirSync(target); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Output: