Path.parents

Path[] parents() const

Returns all ancestor directories as an array of Path.

Performance:

  • Known limitation: This method has O(n²) complexity where n is the path

depth, due to repeated string allocations when calling parent() and str() in a loop. For typical filesystem paths (depth < 20), this is negligible. Deep paths (e.g., 1000+ components) may see performance degradation.

Returns

An array of parent directories, from immediate parent up to the root.