Last active
August 29, 2019 05:01
-
-
Save vjandrei/781b2edd1ce07f60548cf650a99cd6dd to your computer and use it in GitHub Desktop.
create folder and single file on to it
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
const path = require('path'); | |
const mkdirp = require('mkdirp-promise'); | |
const fs = require('fs-extra') | |
let dirs = [ | |
"foldername1", | |
"foldername2", | |
"foldername3" | |
]; | |
const file = 'json.txt' | |
const makeAllDirs = (root, list) => { | |
return list.reduce((p, item) => { | |
return p.then(() => { | |
return mkdirp(path.join(root, item)); | |
}); | |
}, Promise.resolve()); | |
} | |
makeAllDirs(__dirname, dirs).then(() => { | |
// all done here | |
dirs.forEach(function(element) { | |
console.log(element); | |
fs.outputFile('./' + element + '/' + file, 'hello!', err => {}) | |
}); | |
}).catch(err => { | |
// error here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment