Skip to content

Instantly share code, notes, and snippets.

@rgunindi
Forked from mattes/check.go
Created April 14, 2022 21:25
Show Gist options
  • Save rgunindi/561342e5b3958fb0c19f12b9cf39adc5 to your computer and use it in GitHub Desktop.
Save rgunindi/561342e5b3958fb0c19f12b9cf39adc5 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