Last active
August 9, 2020 00:41
-
-
Save huang-x-h/b48e1ea3cd4e1561ed43 to your computer and use it in GitHub Desktop.
mkdir recursive
This file contains hidden or 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
// path需以斜杠结尾 | |
var fs = require('fs'), | |
path = 'base/base/base/'; | |
path.split('/').reduce(function(prev, next) { | |
if (!fs.existsSync(prev)) | |
fs.mkdirSync(prev); | |
return prev + '/' + next; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(for future pple who find this) as of node 10 you can use
fs.mkdirSync(path, {recursive: true})