In Go, is it possible to get the root directory of a path so that
foo/bar/file.txt
returns foo
? I know about path/filepath, but
package main
import (
"fmt"
"path/filepath"
)
func main() {
parts := filepath.SplitList("foo/bar/file.txt")
fmt.Println(parts[0])
fmt.Println(len(parts))
}
prints foo/bar/file.txt
and 1
whereas I would have expected foo
and 3
.