Skip to content

Instantly share code, notes, and snippets.

@sjas
Forked from mattes/check.go
Created June 2, 2018 23:12
Show Gist options
  • Save sjas/1c7f4c957d410a0274f62fe63c4f422e to your computer and use it in GitHub Desktop.
Save sjas/1c7f4c957d410a0274f62fe63c4f422e 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