Extract a part of the filepath (a directory) in Python

I need to extract the name of the parent directory of a certain path. This is what it looks like:

C:\stuff\directory_i_need\subdir\file.jpg

I would like to extract directory_i_need.

7 Answers
7

Leave a Comment