add mkdirSyncRecursive() #7
Labels
No labels
Bug
Enhancement
Feature Request
No milestone
No project
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set.
Reference: code/wrench-js#7
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
It'd be useful to have a mkdirSyncRecursive() in wrench that allowed creation of 'foo/bar' regardless of whether 'foo' existed ahead of time.
I'm certainly down to have one, but I don't have the free time at the moment to spare on getting this in (as simple as it actually may be). If anyone wants to fork/pull request, I'm happy to review and bring it in/push to NPM; otherwise, probably a week or two away.
I'll write a patch at some point if this becomes annoying enough :)
For now I figured it was just better to have the issue logged here, rather than randomly somewhere else (I wasn't expecting you to just write me a patch).
Cheers,
Dave
Here is my implementation of the function. Feel free to use it however you want.
var mkDirSyncRecursive = function mkDirSyncRecursive(path, mode) {
try {
console.log("Creating dir: "+path);
fs.mkdirSync(path, mode);
console.log("...created");
} catch(err) {
if(err.code == "ENOENT") {
console.log("path does not exists yet: "+path);
var slashIdx = path.lastIndexOf("/");
if(slashIdx > 0) {
var parentPath = path.substring(0, slashIdx);
mkDirSyncRecursive(parentPath, mode);
mkDirSyncRecursive(path, mode);
} else {
console.log("No more parent directory. Ending here with error." + err);
throw err;
}
} else if(err.code == "EEXIST") {
console.log("Directory already exists.");
return;
} else {
console.log(err);
throw err;
}
}
}
Thanks! Will get this in later tonight.
I missed tagging this commit with the issue number: 6e7dcba6a00ae433a86d6035827b27f86a735d74
Ah, you guys rock! Will get all this into the mainline repo soon; doing an apartment shuffle at the moment that's screwing with my coding time. >_<;
Hey! Thanks again for all of this; I've pulled it in and published a new version. Need to find time to write tests, augh...