View source code Display the source code in std/path.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.path.dirName

Returns the directory part of a path. On Windows, this includes the drive letter if present.

Prototype

auto dirName(R)(
  R path
)
if (isRandomAccessRange!R && hasSlicing!R && hasLength!R && isSomeChar!(ElementType!R) || is(StringTypeOf!R));

Parameters

NameDescription
path A path name.

Returns

A slice of path or ".".

Examples

assert (dirName("file")        == ".");
assert (dirName("dir/file")    == "dir");
assert (dirName("/file")       == "/");
assert (dirName("dir/subdir/") == "dir");

version (Windows)
{
    assert (dirName("d:file")      == "d:");
    assert (dirName(d:\dir\file) == d:\dir);
    assert (dirName(d:\file)     == d:\);
    assert (dirName(dir\subdir\) == dir);
}

Standards

This function complies with the POSIX requirements for the 'dirname' shell utility (with suitable adaptations for Windows paths).

Authors

Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu

License

Boost License 1.0

Comments