Skip to content

Instantly share code, notes, and snippets.

@farhany
Forked from mattes/check.go
Created May 22, 2019 18:26
Show Gist options
  • Save farhany/4d2e63b6fe8a1b68cf6fc66e0d886cf6 to your computer and use it in GitHub Desktop.
Save farhany/4d2e63b6fe8a1b68cf6fc66e0d886cf6 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