chdir

Change directory to pathname. Equivalent to cd on Windows and POSIX.

  1. void chdir(R pathname)
  2. void chdir(R pathname)
    void
    chdir
    (
    R
    )
    (
    auto ref R pathname
    )

Parameters

pathname R

the directory to step into

Throws

FileException on error.

Examples

import std.algorithm.comparison : equal;
import std.algorithm.sorting : sort;
import std.array : array;
import std.path : buildPath;

auto cwd = getcwd;
auto dir = deleteme ~ "dir";
dir.mkdir;
scope(exit) cwd.chdir, dir.rmdirRecurse;

dir.buildPath("a").write(".");
dir.chdir; // step into dir
"b".write(".");
assert(dirEntries(".", SpanMode.shallow).array.sort.equal(
    [".".buildPath("a"), ".".buildPath("b")]
));

Meta