Skip to content

Instantly share code, notes, and snippets.

@goldalworming
Forked from mattes/check.go
Created April 11, 2016 07:47
Show Gist options
  • Select an option

  • Save goldalworming/727c8b1ec58c4a033ecad08bc95a4f7f to your computer and use it in GitHub Desktop.

Select an option

Save goldalworming/727c8b1ec58c4a033ecad08bc95a4f7f 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"); err == nil {
// path/to/whatever exists
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment