Skip to content

Instantly share code, notes, and snippets.

@lanzafame
Forked from mattes/check.go
Last active June 17, 2016 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lanzafame/4718052bb17794c71db1ef4e9a4b5e49 to your computer and use it in GitHub Desktop.
Save lanzafame/4718052bb17794c71db1ef4e9a4b5e49 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