relativeTo

Create a path from p that is relative to parent.

relativeTo
(
PathType
)
(
auto ref in PathType p
,
in auto ref PathType parent
)
if (
isSomePath!PathType
)

Examples

import std.exception : assertThrown;

assertEqual(Path("C:/hello/world.exe").relativeTo(Path("C:/hello")), Path("world.exe"));
assertEqual(Path("C:/hello").relativeTo(Path("C:/hello")), Path());
assertEqual(Path("C:/hello/").relativeTo(Path("C:/hello")), Path());
assertEqual(Path("C:/hello").relativeTo(Path("C:/hello/")), Path());
assertEqual(WindowsPath("C:/foo/bar/baz").relativeTo(WindowsPath("C:/foo")), WindowsPath(`bar\baz`));
assertEqual(PosixPath("C:/foo/bar/baz").relativeTo(PosixPath("C:/foo")), PosixPath("bar/baz"));
assertThrown!PathException(Path("a").relativeTo(Path("b")));

Meta