Skip to content

Instantly share code, notes, and snippets.

@delputnam
Created February 23, 2016 21:01
Show Gist options
  • Save delputnam/bc27fdd9456577713a3f to your computer and use it in GitHub Desktop.
Save delputnam/bc27fdd9456577713a3f to your computer and use it in GitHub Desktop.
Check for existence of file using golang
if _, err := os.Stat("/path/to/file/or/dir"); os.IsNotExist(err) {
// /path/to/file/or/dir does not exist
}
if _, err := os.Stat("/path/to/file/or/dir"); err == nil {
// /path/to/file/or/dir exists
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment