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.
{null} buildNormalizedPath(C)()
if (isSomeChar!C);
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.
Parameters
Name | Description |
---|---|
paths | An array of paths to assemble. |
Returns
The assembled path.
Example
writeln(buildNormalizedPath("foo", "..")); // "."
version (Posix)
{
writeln(buildNormalizedPath("/foo/./bar/..//baz/")); // "/foo/baz"
writeln(buildNormalizedPath("../foo/.")); // "../foo"
writeln(buildNormalizedPath("/foo", "bar/baz/")); // "/foo/bar/baz"
writeln(buildNormalizedPath("/foo", "/bar/..", "baz")); // "/baz"
writeln(buildNormalizedPath("foo/./bar", "../../", "../baz")); // "../baz"
writeln(buildNormalizedPath("/foo/./bar", "../../baz")); // "/baz"
}
version (Windows)
{
writeln(buildNormalizedPath(`c:\foo\.\bar/..\\baz\`)); // `c:\foo\baz`
writeln(buildNormalizedPath(`..\foo\.`)); // `..\foo`
writeln(buildNormalizedPath(`c:\foo`, `bar\baz\`)); // `c:\foo\bar\baz`
writeln(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