Skip to content

Instantly share code, notes, and snippets.

@Chever-John
Forked from mattes/check.go
Created February 4, 2023 03:44
Show Gist options
  • Save Chever-John/b4f917c1eeddf6b99e691983612c0507 to your computer and use it in GitHub Desktop.
Save Chever-John/b4f917c1eeddf6b99e691983612c0507 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"); !os.IsNotExist(err) {
// path/to/whatever exists
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment