Skip to content

Instantly share code, notes, and snippets.

@dkbrummitt
Forked from mattes/check.go
Created August 27, 2019 09:08
Show Gist options
  • Save dkbrummitt/9db249c14a8fc15d9efa8d76a3e970fd to your computer and use it in GitHub Desktop.
Save dkbrummitt/9db249c14a8fc15d9efa8d76a3e970fd 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