Skip to content

Instantly share code, notes, and snippets.

@flannel
Forked from mattes/check.go
Created January 19, 2016 17:49
Show Gist options
  • Save flannel/42b627d9b4adab9e9a22 to your computer and use it in GitHub Desktop.
Save flannel/42b627d9b4adab9e9a22 to your computer and use it in GitHub Desktop.
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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment