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.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
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.