dictIO.utils.path

Utility functions for working with paths.

Functions

highest_common_root_folder(paths)

Return the highest common root folder among the passed in paths.

relative_path(from_path, to_path)

Return the relative path from one path to another.

dictIO.utils.path.highest_common_root_folder(paths: Sequence[Path]) → Path

Return the highest common root folder among the passed in paths.

Paths with a suffix are treated as files, so their parent directories participate in the common-root calculation.

Parameters:

paths (Sequence[Path]) – Paths to files or folders.

Returns:

The highest common directory shared by all input paths.

Raises:

ValueError – If paths is empty or the paths do not share a common root.

Return type:

Path

dictIO.utils.path.relative_path(from_path: Path, to_path: Path) → Path

Return the relative path from one path to another.

First resolve the relative path using Path.relative_to; if the target is outside the source path, calculate a relative path using the operating system path rules.

Parameters:
  • from_path (Path) – Starting path.

  • to_path (Path) – Target path.

Returns:

Path from the starting path to the target path.

Raises:

ValueError – If neither path operation can calculate a relative path.

Return type:

Path