Introduction
The filepath
package in Golang provides functions to parse and construct file paths in a way that is portable between operating systems.
This tutorial is from open-source community. Access the source code
The filepath
package in Golang provides functions to parse and construct file paths in a way that is portable between operating systems.
In this challenge, you need to use the filepath
package to perform various operations on file paths, such as constructing paths in a portable way, splitting a path into directory and file components, checking whether a path is absolute, finding the extension of a file, and finding a relative path between two paths.
Join
to construct paths in a portable way.Dir
and Base
to split a path into directory and file components.IsAbs
to check whether a path is absolute.Ext
to find the extension of a file.TrimSuffix
to remove the extension from a file name.Rel
to find a relative path between two paths.$ go run file-paths.go
p: dir1/dir2/filename
dir1/filename
dir1/filename
Dir(p): dir1/dir2
Base(p): filename
false
true
.json
config
t/file
../c/t/file
The filepath
package in Golang provides functions to work with file paths in a portable way. By using these functions, you can construct paths, split them into directory and file components, check whether they are absolute, find the extension of a file, and find a relative path between two paths.