You should use the os.Stat()
and os.IsNotExist()
functions as in the following example:
// Exists reports whether the named file or directory exists.
func Exists(name string) bool {
if _, err := os.Stat(name); err != nil {
if os.IsNotExist(err) {
return false
}
}
return true
}
The example is extracted from here.