Path.parents: Get the Parent Directory of a File

Path.parents: Get the Parent Directory of a File

If you want to get the parent directory of a file, use Path(file).parents[index].

Path(file).parents[0] gets the parent directory one level up. Path(file).parents[1] gets the parent directory two levels up.

Find an example of this method in the code above.

Link to the source code.

Search

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran