Skip to content

Instantly share code, notes, and snippets.

@sakishen
Forked from mattes/check.go
Created November 28, 2019 06:54
Show Gist options
  • Save sakishen/a0a9a02a94a3bda4c586b7d6171d6bc1 to your computer and use it in GitHub Desktop.
Save sakishen/a0a9a02a94a3bda4c586b7d6171d6bc1 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