Return the absolute path of a file.
filepath.Abs returns an absolute representation of path. If the path is not absolute, it is joined with the current working directory to turn it into an absolute path.
The returned path is cleaned as if by filepath.Clean. filepath.Abs calls os.Getwd to obtain the current directory if needed.
filepath.Abs is commonly used to normalize relative paths into absolute paths for reliable file operations.
| Name | Description | Optional |
|---|---|---|
path |
The file path to convert to absolute. | No |
abs, err := filepath.Abs("file.txt")
if err != nil {
log.Fatal(err)
}
fmt.Println(abs) // /home/user/project/file.txt