View source code
Display the source code in std/path.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

Function std.path.rootName

Returns the root directory of the specified path, or null if the path is not rooted.

auto rootName(R) (
  R path
)
if (isRandomAccessRange!R && hasSlicing!R && hasLength!R && isSomeChar!(ElementType!R) && !isSomeString!R);

auto rootName(C) (
  C[] path
)
if (isSomeChar!C);

Parameters

NameDescription
path A path name.

Returns

A slice of path.

Example

assert(rootName("") is null);
assert(rootName("foo") is null);
writeln(rootName("/")); // "/"
writeln(rootName("/foo/bar")); // "/"

version (Windows)
{
    assert(rootName("d:foo") is null);
    writeln(rootName(`d:\foo`)); // `d:\`
    writeln(rootName(`\\server\share\foo`)); // `\\server\share`
    writeln(rootName(`\\server\share`)); // `\\server\share`
}

Authors

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

License

Boost License 1.0