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