The OpenD Programming Language

mkdirRecurse

Make directory and all parent directories as needed.

Does nothing if the directory specified by pathname already exists.

@safe
void
mkdirRecurse
(
scope const(char)[] pathname
)

Parameters

pathname const(char)[]

the full path of the directory to create

Throws

FileException on error.

Examples

import std.path : buildPath;

auto dir = deleteme ~ "dir";
scope(exit) dir.rmdirRecurse;

dir.mkdir;
assert(dir.exists);
dir.mkdirRecurse; // does nothing

// creates all parent directories as needed
auto nested = dir.buildPath("a", "b", "c");
nested.mkdirRecurse;
assert(nested.exists);
import std.exception : assertThrown;

scope(exit) deleteme.remove;
deleteme.write("a");

// cannot make directory as it's already a file
assertThrown!FileException(deleteme.mkdirRecurse);

Meta