Get parent directory in Python
Posted
by Mridang Agarwalla
on Stack Overflow
See other posts from Stack Overflow
or by Mridang Agarwalla
Published on 2010-05-18T18:55:41Z
Indexed on
2010/05/18
19:00 UTC
Read the original article
Hit count: 484
python
Hi,
Could someone tell me how to get the parent directory of a path in Python in a cross platform way. E.g.
C:\Program Files ---> C:\
and
C:\ ---> C:\
If the directory doesn't have a parent directory, it returns the directory itself. The question might seem simple but I couldn't dig it up through Google.
Thanks.
© Stack Overflow or respective owner