Created
November 21, 2013 04:30
-
-
Save euforic/7576123 to your computer and use it in GitHub Desktop.
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
function mkdirP (p, fn, made) { | |
if (!made) made = null; | |
var cb = fn || function () {}; | |
p = path.resolve(p); | |
fs.mkdir(p, function (err) { | |
if (!err) return cb(null, made || p); | |
if (err.code != 'ENOENT') return err; | |
mkdirP(path.dirname(p), mode, function (err, made) { | |
if (err) cb(err, made); | |
return mkdirP(p, cb, made); | |
}); | |
}); | |
} | |
/** | |
* usage | |
*/ | |
mkdirP('/Users/euforic/test_cases/mkdirP', function(){ | |
console.log(fs.existsSync('/Users/euforic/test_cases/mkdirP')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@candrade ^^