Path.parts

string[] parts() const @safe

Split the path into components similar to Python's pathlib parts.

Platform semantics:

  • POSIX: Absolute paths include the root "/" as the first element. Relative paths do not.

Examples

Path("/a/b").parts -> ["/", "a", "b"], Path("a/b").parts -> ["a", "b"].
  • Windows: The first element is the anchor when present (drive+root for absolute paths, e.g. "C:\\";

UNC anchor like "\\\\server\\share\\"; or drive-only anchor like "C:").

Examples:

  • Path("C:/a/b").parts -> ["C:\\", "a", "b"]
  • Path("C:a/b").parts -> ["C:", "a", "b"]
  • Path("\\\\server\\share\\a").parts -> ["\\\\server\\share\\", "a"]
  • Path("\\a\\b").parts -> ["\\", "a", "b"]

Returns

An array of path components.