Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
Tips & Traps¶
There is no built-in function to check for the existence of a path in Golang.
However,
you can achieve it using os.Stat + os.IsNotExist.
import "os"_, err := os.Stat("/some/non-exist/path")errstat /some/non-exist/path: no such file or directoryos.IsNotExist(err)trueThe function ExistsPath below is an implementation based the idea abvoe.
func ExistsPath(path string) bool {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return false
}
return true
}ExistsPath("/some/non-exist/path")false