Function relativeTo
Computes the relative path from base_path
to this path.
Path relativeTo(Path)
(
Path path,
Path base_path
) @safe
if (isInstanceOf!(GenericPath, Path));
Parameters
Name | Description |
---|---|
path | The destination path |
base_path | The path from which the relative path starts |
See also
Example
import std .array : array;
import std .conv : to;
assert(PosixPath("/some/path") .relativeTo(PosixPath("/")) == PosixPath("some/path"));
assert(PosixPath("/some/path/") .relativeTo(PosixPath("/some/other/path/")) == PosixPath("../../path/"));
assert(PosixPath("/some/path/") .relativeTo(PosixPath("/some/other/path")) == PosixPath("../../path/"));
assert(WindowsPath("C:\\some\\path") .relativeTo(WindowsPath("C:\\")) == WindowsPath("some\\path"));
assert(WindowsPath("C:\\some\\path\\") .relativeTo(WindowsPath("C:\\some\\other\\path/")) == WindowsPath("..\\..\\path\\"));
assert(WindowsPath("C:\\some\\path\\") .relativeTo(WindowsPath("C:\\some\\other\\path")) == WindowsPath("..\\..\\path\\"));
assert(WindowsPath("\\\\server\\share\\some\\path") .relativeTo(WindowsPath("\\\\server\\share\\")) == WindowsPath("some\\path"));
assert(WindowsPath("\\\\server\\share\\some\\path\\") .relativeTo(WindowsPath("\\\\server\\share\\some\\other\\path/")) == WindowsPath("..\\..\\path\\"));
assert(WindowsPath("\\\\server\\share\\some\\path\\") .relativeTo(WindowsPath("\\\\server\\share\\some\\other\\path")) == WindowsPath("..\\..\\path\\"));
assert(WindowsPath("C:\\some\\path") .relativeTo(WindowsPath("D:\\")) == WindowsPath("C:\\some\\path"));
assert(WindowsPath("C:\\some\\path\\") .relativeTo(WindowsPath("\\\\server\\share")) == WindowsPath("C:\\some\\path\\"));
assert(WindowsPath("\\\\server\\some\\path\\") .relativeTo(WindowsPath("C:\\some\\other\\path")) == WindowsPath("\\\\server\\some\\path\\"));
assert(WindowsPath("\\\\server\\some\\path\\") .relativeTo(WindowsPath("\\\\otherserver\\path")) == WindowsPath("\\\\server\\some\\path\\"));
assert(WindowsPath("\\some\\path\\") .relativeTo(WindowsPath("\\other\\path")) == WindowsPath("..\\..\\some\\path\\"));
assert(WindowsPath("\\\\server\\share\\path1") .relativeTo(WindowsPath("\\\\server\\share\\path2")) == WindowsPath("..\\path1"));
assert(WindowsPath("\\\\server\\share\\path1") .relativeTo(WindowsPath("\\\\server\\share2\\path2")) == WindowsPath("\\\\server\\share\\path1"));
assert(WindowsPath("\\\\server\\share\\path1") .relativeTo(WindowsPath("\\\\server2\\share2\\path2")) == WindowsPath("\\\\server\\share\\path1"));