path/filepathCross-platform filesystem paths (not URL paths — use net/url or path for those).
import "path/filepath"
p := filepath.Join("a", "b", "c.txt")
clean := filepath.Clean(`a/../b/./c`)
base := filepath.Base(p) // file name
dir := filepath.Dir(p) // directory
ext := filepath.Ext(p) // suffix including dot
rel, err := filepath.Rel("/a/b", "/a/b/c/d")
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() && d.Name() == ".git" {
return filepath.SkipDir
}
return nil
})
Prefer io/fs.WalkDir with os.DirFS when working with fs.FS abstractions.
filepath adapts separators; do not hand-build strings with / for Windows-only edge cases without tests.
os.PathSeparator / ListSeparatorWhen constructing PATH-style variables.