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
.
directoryfilepathpython
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
.
Best Answer
And you can continue doing this as many times as necessary...
Edit: from os.path, you can use either os.path.split or os.path.basename: