The OpenD Programming Language

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.

@safe pure nothrow
immutable(C)[]
buildNormalizedPath
(
C
)
(
const(C[])[] paths...
)

Parameters

paths const(C[])[]

An array of paths to assemble.

Return Value

Type: immutable(C)[]

The assembled path.

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`);
}

Meta