Skip to content

Instantly share code, notes, and snippets.

@ramitsurana
Forked from mattes/check.go
Created July 28, 2016 16:40
Show Gist options
  • Save ramitsurana/a010c6d1fd8e9770c173044e0fc598a3 to your computer and use it in GitHub Desktop.
Save ramitsurana/a010c6d1fd8e9770c173044e0fc598a3 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