Posted on 25th July 2024|27 views
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 25th July 2024| views
Try this
>>> os.path.dirname(r'C:\Program Files')
'C:\\'
>>> os.path.dirname('C:\\')
'C:\\'