Path.parents: Get the Parent Directory of a File

Table of Contents

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.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran