| 248 | } |
| 249 | |
| 250 | func GetDirectoryPath(path string) string { |
| 251 | path = NormalizeSlashes(path) |
| 252 | |
| 253 | // If the path provided is itself a root, then return it. |
| 254 | rootLength := GetRootLength(path) |
| 255 | if rootLength == len(path) { |
| 256 | return path |
| 257 | } |
| 258 | |
| 259 | // return the leading portion of the path up to the last (non-terminal) directory separator |
| 260 | // but not including any trailing directory separator. |
| 261 | path = RemoveTrailingDirectorySeparator(path) |
| 262 | return path[:max(rootLength, strings.LastIndex(path, "/"))] |
| 263 | } |
| 264 | |
| 265 | func (p Path) GetDirectoryPath() Path { |
| 266 | return Path(GetDirectoryPath(string(p))) |