lanzafame
6/17/2016 - 1:44 AM

Check if file or directory exists in Golang

Check if file or directory exists in Golang

if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) {
	// path/to/whatever does not exist
}

if _, err := os.Stat("/path/to/whatever"); err == nil {
	// path/to/whatever exists
}