Skip to content

Instantly share code, notes, and snippets.

@Narven
Forked from mattes/check.go
Created February 25, 2021 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Narven/4922eadbd09213767a2afe99aa7cfbbd to your computer and use it in GitHub Desktop.
Save Narven/4922eadbd09213767a2afe99aa7cfbbd 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"); !os.IsNotExist(err) {
// path/to/whatever exists
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment