get the parent directory name in go

main.go
package main

import (
    "fmt"
    "os"
    "path/filepath"
)

func main() {
    path := "/path/to/directory/file.txt"
    parent := filepath.Base(filepath.Dir(path))
    fmt.Println(parent)
}
195 chars
14 lines

related categories

gistlibby LogSnag