string or random access range representing the path to normalize
normalized path as a forward range
import std.array; assert(asNormalizedPath("foo/..").array == "."); version (Posix) { assert(asNormalizedPath("/foo/./bar/..//baz/").array == "/foo/baz"); assert(asNormalizedPath("../foo/.").array == "../foo"); assert(asNormalizedPath("/foo/bar/baz/").array == "/foo/bar/baz"); assert(asNormalizedPath("/foo/./bar/../../baz").array == "/baz"); } version (Windows) { assert(asNormalizedPath(`c:\foo\.\bar/..\\baz\`).array == `c:\foo\baz`); assert(asNormalizedPath(`..\foo\.`).array == `..\foo`); assert(asNormalizedPath(`c:\foo\bar\baz\`).array == `c:\foo\bar\baz`); assert(asNormalizedPath(`c:\foo\bar/..`).array == `c:\foo`); assert(asNormalizedPath(`\\server\share\foo\..\bar`).array == `\\server\share\bar`); }
Normalize a path by 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 asNormalizedPath on empty paths will always return an empty path.
Does not resolve symbolic links.
This function always allocates memory to hold the resulting path. Use buildNormalizedPath to allocate memory and return a string.