Guest User

Untitled

a guest
Jul 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. const fs = require('fs')
  2. const Path = require('path')
  3.  
  4. function mkdirs(path, p) {
  5. if (p === undefined) {
  6. p = path.length
  7. path = Path.resolve(path)
  8. }
  9. try {
  10. fs.mkdirSync(path)
  11. } catch (err) {
  12. if (err.code === 'EEXIST') { return }
  13. if (err.code !== 'ENOENT') { throw err }
  14. p = path.lastIndexOf('/', p)
  15. if (p == -1 || p == 0) {
  16. throw new Error('unable to create root directory')
  17. }
  18. mkdirs(path.substr(0, p), p)
  19. try {
  20. fs.mkdirSync(path)
  21. } catch (err) {
  22. // in case another process won the race
  23. if (err.code !== 'EEXIST') { throw err }
  24. }
  25. }
  26. }
Add Comment
Please, Sign In to add comment