Created
December 3, 2013 15:33
-
-
Save tueda/7771237 to your computer and use it in GitHub Desktop.
Ensures the given path is created. For Mathematica 7+.
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
(* | |
* Makes a directory tree. | |
*) | |
EnsurePath[path_String] := Module[{names, cd, p}, | |
names = FileNameSplit[path]; | |
cd = {}; | |
While[Length[names] > 0, | |
AppendTo[cd, First[names]]; | |
names = Rest[names]; | |
p = FileNameJoin[cd]; | |
If[!DirectoryQ[p], | |
If[CreateDirectory[p] === $Failed, | |
Return[$Failed]; | |
]; | |
]; | |
]; | |
path | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It turned out that If[!DirectoryQ["path"],CreateDirectory["path"]] is enough due to the default setting CreateIntermediateDirectories->True.