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.buildNormalizedPath

Performs the same task as buildPath, while at the same time resolving current/parent directory symbols ("." and "..") and removing superfluous directory separators. It will return "." if the path leads to the starting directory. On Windows, slashes are replaced with backslashes.

Using buildNormalizedPath on null paths will always return null.

Note that this function does not resolve symbolic links.

This function always allocates memory to hold the resulting path. Use asNormalizedPath to not allocate memory.

Prototype

immutable(C)[] buildNormalizedPath(C)(
  const(C[])[] paths
) pure nothrow @trusted
if (isSomeChar!C);

Examples

assert (buildNormalizedPath("foo", "..") == ".");

version (Posix)
{
    assert (buildNormalizedPath("/foo/./bar/..//baz/") == "/foo/baz");
    assert (buildNormalizedPath("../foo/.") == "../foo");
    assert (buildNormalizedPath("/foo", "bar/baz/") == "/foo/bar/baz");
    assert (buildNormalizedPath("/foo", "/bar/..", "baz") == "/baz");
    assert (buildNormalizedPath("foo/./bar", "../../", "../baz") == "../baz");
    assert (buildNormalizedPath("/foo/./bar", "../../baz") == "/baz");
}

version (Windows)
{
    assert (buildNormalizedPath(c:\foo\.\bar/..\\baz\) == c:\foo\baz);
    assert (buildNormalizedPath(..\foo\.) == ..\foo);
    assert (buildNormalizedPath(c:\foo, bar\baz\) == c:\foo\bar\baz);
    assert (buildNormalizedPath(c:\foo, bar/..) == c:\foo);
    assert (buildNormalizedPath(\\server\share\foo, ..\bar) == \\server\share\bar);
}

Authors

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

License

Boost License 1.0

Comments