Skip to content

Instantly share code, notes, and snippets.

@cavalcantegb
Forked from mattes/check.go
Created October 4, 2019 19:29
Show Gist options
  • Select an option

  • Save cavalcantegb/0ff8ec01439f04402e8ccf320e9e12a3 to your computer and use it in GitHub Desktop.

Select an option

Save cavalcantegb/0ff8ec01439f04402e8ccf320e9e12a3 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