Skip to content

Instantly share code, notes, and snippets.

@dink10
Forked from mattes/check.go
Created February 12, 2018 10:04
Show Gist options
  • Save dink10/62b0918454a4b1f7953e7471918cf17d to your computer and use it in GitHub Desktop.
Save dink10/62b0918454a4b1f7953e7471918cf17d 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