Post
Python
How can I get the parent directory in python?
can I get a parent directory of a path in a cross-platform method just like this
C:\Program Files ---> C:\ and C:\ ---> C:\
Posted on 26th April 2024
Try this
>>> os.path.dirname(r'C:\Program Files')
'C:\\'
>>> os.path.dirname('C:\\')
'C:\\'
STILL GOT QUERIES?