By using the path/filepath
package with the following example, you can get the full directory path from a file path.
package main
import (
"fmt"
"path/filepath"
)
func main() {
// Output: /path/to/dir
fmt.Println(filepath.Dir("/path//to/dir/file.ext"))
}
But is there a Parent
function to get the dir
from the path? (which is the name of the directory of the file):
// The `Parent` is what I want,
// and this is a pseudo-code example, this won't actually work.
//
// Output: dir
fmt.Println(filepath.Parent("/path//to/dir/file.ext"))
If it can't be done with the functions, how do I get the parent's name with RegExp?
filepath.Dir
andfilepath.Base
? – Whereon