File paths
Context
Section titled “Context”The path/filepath package provides cross‑platform path manipulation: joining, splitting, cleaning, and relative paths.
Example
Section titled “Example”Join paths, get base and directory.
Code example
Section titled “Code example”package main
import ( "fmt" "path/filepath")
func main() { path := filepath.Join("dir", "subdir", "file.txt") fmt.Println("Joined:", path)
fmt.Println("Base:", filepath.Base(path)) fmt.Println("Dir:", filepath.Dir(path)) fmt.Println("Ext:", filepath.Ext(path)) fmt.Println("Abs?", filepath.IsAbs(path))}Output
Section titled “Output”Joined: dir/subdir/file.txtBase: file.txtDir: dir/subdirExt: .txtAbs? false