path to transform
absolute path
whether filespec comparisons are sensitive or not; defaults to CaseSensitive.osDefault
a random access range of the transformed path
import std.array; version (Posix) { assert(asRelativePath("foo", "/bar").array == "foo"); assert(asRelativePath("/foo/bar", "/foo/bar").array == "."); assert(asRelativePath("/foo/bar", "/foo/baz").array == "../bar"); assert(asRelativePath("/foo/bar/baz", "/foo/woo/wee").array == "../../bar/baz"); assert(asRelativePath("/foo/bar/baz", "/foo/bar").array == "baz"); } else version (Windows) { assert(asRelativePath("foo", `c:\bar`).array == "foo"); assert(asRelativePath(`c:\foo\bar`, `c:\foo\bar`).array == "."); assert(asRelativePath(`c:\foo\bar`, `c:\foo\baz`).array == `..\bar`); assert(asRelativePath(`c:\foo\bar\baz`, `c:\foo\woo\wee`).array == `..\..\bar\baz`); assert(asRelativePath(`c:/foo/bar/baz`, `c:\foo\woo\wee`).array == `..\..\bar\baz`); assert(asRelativePath(`c:\foo\bar\baz`, `c:\foo\bar`).array == "baz"); assert(asRelativePath(`c:\foo\bar`, `d:\foo`).array == `c:\foo\bar`); assert(asRelativePath(`\\foo\bar`, `c:\foo`).array == `\\foo\bar`); } else static assert(0);
Transforms path into a path relative to base.
The returned path is relative to base, which is usually the current working directory. base must be an absolute path, and it is always assumed to refer to a directory. If path and base refer to the same directory, the function returns '.'.
The following algorithm is used:
In the second step, path components are compared using filenameCmp!cs, where cs is an optional template parameter determining whether the comparison is case sensitive or not. See the filenameCmp documentation for details.