Path.parents
Path[] parents() constReturns all ancestor directories as an array of Path, pathlib-style.
The list starts with the immediate parent and ends with the path's anchor: the root (`/`) for absolute POSIX paths, the drive/UNC root for absolute Windows paths, and `.` for relative paths. Termination is structural (parent() strictly shortens the path); a defensive same-as-previous guard replaces any depth cap.
Performance:
- Known limitation: This method has O(n²) complexity where n is the path depth, due to repeated string allocations when calling
parent()andstr()in a loop. For typical filesystem paths (depth < 20), this is negligible.Returns
An array of parent directories, from immediate parent up to and including the anchor.