summaryrefslogtreecommitdiffstats
path: root/libgo/go/path/path.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/path/path.go')
-rw-r--r--libgo/go/path/path.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/libgo/go/path/path.go b/libgo/go/path/path.go
index 235384667c6..20d89c9ff0c 100644
--- a/libgo/go/path/path.go
+++ b/libgo/go/path/path.go
@@ -160,3 +160,21 @@ func Base(path string) string {
func IsAbs(path string) bool {
return len(path) > 0 && path[0] == '/'
}
+
+// Dir returns the all but the last element of path, typically the path's directory.
+// Trailing path separators are removed before processing.
+// If the path is empty, Dir returns ".".
+// If the path consists entirely of separators, Dir returns a single separator.
+// The returned path does not end in a separator unless it is the root directory.
+func Dir(path string) string {
+ dir, _ := Split(path)
+ dir = Clean(dir)
+ last := len(dir) - 1
+ if last > 0 && dir[last] == '/' {
+ dir = dir[:last]
+ }
+ if dir == "" {
+ dir = "."
+ }
+ return dir
+}
OpenPOWER on IntegriCloud