Standard library / path/filepath
path/filepath.Clean()
Normalizes path elements lexically using host OS rules; does not resolve links or validate access. Example uses a disposable temporary workspace. Expected stdout: 'b/c\n'.
Formal Syntax & Structure
go syntaxgo
func Clean(path string) stringParameters & Attributes
| Name | Type | Description |
|---|---|---|
| path | string | Pathname interpreted according to this package. |
Return Value
string
Normalizes path elements lexically using host OS rules; does not resolve links or validate access.
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "path/filepath")
func check(e error) { if e != nil { panic(e) }}func workspace() func() { root, e := os.MkdirTemp("", "bytemind-go-") check(e) old, e := os.Getwd() check(e) check(os.Chdir(root)) return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() { defer workspace()(); fmt.Println(filepath.Clean("a/../b//c")) }