Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

add mkdirSyncRecursive() #7

Closed
neerolyte opened this issue Oct 16, 2011 · 7 comments
Closed

add mkdirSyncRecursive() #7

neerolyte opened this issue Oct 16, 2011 · 7 comments

Comments

@neerolyte
Copy link
Contributor

It'd be useful to have a mkdirSyncRecursive() in wrench that allowed creation of 'foo/bar' regardless of whether 'foo' existed ahead of time.

@ryanmcgrath
Copy link
Owner

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.

@neerolyte
Copy link
Contributor Author

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

@nherment
Copy link

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;
}
}
}

@ryanmcgrath
Copy link
Owner

Thanks! Will get this in later tonight.

neerolyte added a commit to neerolyte/wrench-js that referenced this issue Oct 21, 2011
neerolyte added a commit to neerolyte/wrench-js that referenced this issue Oct 21, 2011
@neerolyte
Copy link
Contributor Author

I missed tagging this commit with the issue number: 6e7dcba

@ryanmcgrath
Copy link
Owner

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. >_<;

ryanmcgrath pushed a commit that referenced this issue Oct 23, 2011
@ryanmcgrath
Copy link
Owner

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...

rwmtse added a commit to rwmtse/wrench-js that referenced this issue Feb 6, 2012
ryanmcgrath pushed a commit that referenced this issue Feb 18, 2012
Make sure fix for issue #7 works in Windows too (check for backslash in ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants