Relative path from basepath
How to get a relative path of a target path from a base path in golang?
The function filepath.Rel()
returns a relative path that is lexically equivalent to target path when joined to base path with an intervening separator.
Here is a golang example that shows how to get a relative path of a target path from a base path:
targpath := "/home/dennis/projects"
basepath := "/home/dennis/projects/golang/file1"
relpath, _ := filepath.Rel(targpath,basepath)
fmt.Println("Relative Path:", relpath)
$ go run example.go
Relative Path: golang/file1