Returns the directory component of a pathname
(p)
| 148 | # Return the head (dirname) part of a path, same as split(path)[0]. |
| 149 | |
| 150 | def dirname(p): |
| 151 | """Returns the directory component of a pathname""" |
| 152 | p = os.fspath(p) |
| 153 | sep = _get_sep(p) |
| 154 | i = p.rfind(sep) + 1 |
| 155 | head = p[:i] |
| 156 | if head and head != sep*len(head): |
| 157 | head = head.rstrip(sep) |
| 158 | return head |
| 159 | |
| 160 | |
| 161 | # Is a path a symbolic link? |