Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs')
- const Path = require('path')
- function mkdirs(path, p) {
- if (p === undefined) {
- p = path.length
- path = Path.resolve(path)
- }
- try {
- fs.mkdirSync(path)
- } catch (err) {
- if (err.code === 'EEXIST') { return }
- if (err.code !== 'ENOENT') { throw err }
- p = path.lastIndexOf('/', p)
- if (p == -1 || p == 0) {
- throw new Error('unable to create root directory')
- }
- mkdirs(path.substr(0, p), p)
- try {
- fs.mkdirSync(path)
- } catch (err) {
- // in case another process won the race
- if (err.code !== 'EEXIST') { throw err }
- }
- }
- }
Add Comment
Please, Sign In to add comment