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

1 import std.exception : assertThrown;
2 
3 assertEqual(Path("C:/hello/world.exe").relativeTo(Path("C:/hello")), Path("world.exe"));
4 assertEqual(Path("C:/hello").relativeTo(Path("C:/hello")), Path());
5 assertEqual(Path("C:/hello/").relativeTo(Path("C:/hello")), Path());
6 assertEqual(Path("C:/hello").relativeTo(Path("C:/hello/")), Path());
7 assertEqual(WindowsPath("C:/foo/bar/baz").relativeTo(WindowsPath("C:/foo")), WindowsPath(`bar\baz`));
8 assertEqual(PosixPath("C:/foo/bar/baz").relativeTo(PosixPath("C:/foo")), PosixPath("bar/baz"));
9 assertThrown!PathException(Path("a").relativeTo(Path("b")));

Meta