Skip to content

Instantly share code, notes, and snippets.

@greentornado
Forked from mattes/check.go
Created December 27, 2019 04:44
Show Gist options
  • Save greentornado/2d2f0a1cc366d379038d940e792121b5 to your computer and use it in GitHub Desktop.
Save greentornado/2d2f0a1cc366d379038d940e792121b5 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