June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
29
Task/Make-directory-path/D/make-directory-path.d
Normal file
29
Task/Make-directory-path/D/make-directory-path.d
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
makeDir("parent/test");
|
||||
}
|
||||
|
||||
/// Manual implementation of what mkdirRecurse in std.file does.
|
||||
void makeDir(string path) out {
|
||||
import std.exception : enforce;
|
||||
import std.file : exists;
|
||||
enforce(path.exists, "Failed to create the requested directory.");
|
||||
} body {
|
||||
import std.array : array;
|
||||
import std.file;
|
||||
import std.path : pathSplitter, chainPath;
|
||||
|
||||
auto workdir = "";
|
||||
foreach (dir; path.pathSplitter) {
|
||||
workdir = chainPath(workdir, dir).array;
|
||||
if (workdir.exists) {
|
||||
if (!workdir.isDir) {
|
||||
import std.conv : text;
|
||||
throw new FileException(text("The file ", workdir, " in the path ", path, " is not a directory."));
|
||||
}
|
||||
} else {
|
||||
workdir.mkdir();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue