-
-
Save antonioiksi/3064b58793f70f191e3c9f40f0df9108 to your computer and use it in GitHub Desktop.
create_dir_recursively
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
var fs = require('fs'); | |
/** | |
* Splits whole path into segments and checks each segment for existence and recreates directory tree from the bottom. | |
* If since some segment tree doesn't exist it will be created in series. | |
* Existing directories will be skipped. | |
* @param {String} directory | |
*/ | |
function mkdirSyncRecursive(directory) { | |
var path = directory.replace(/\/$/, '').split('/'); | |
for (var i = 1; i <= path.length; i++) { | |
var segment = path.slice(0, i).join('/'); | |
!fs.existsSync(segment) ? fs.mkdirSync(segment) : null ; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment