Skip to content

PurePath.relativeTo() method

pathlib-ts > PurePath > relativeTo

Return the relative path to another path identified by the passed arguments.

Signature:

relativeTo(other: PathLike, options?: {
walkUp?: boolean;
}): PurePath;

Parameter

Type

Description

other

PathLike

Anchor path used as the reference point.

options

{ walkUp?: boolean; }

(Optional) Optional lexical behaviour toggles (walkUp mirrors CPython 3.12+).

Returns:

PurePath

A new path relative to other.

The Error class When anchors differ or no lexical relationship exists (and walkUp is false).

By default the operation is purely lexical and raises if the target is not an ancestor. Pass options.walkUp = true to allow .. segments. This mirrors CPython and is the foundation for Path.relativeTo policies.