Skip to content

Instantly share code, notes, and snippets.

@kenjitagawa
Forked from mattes/check.go
Created April 22, 2025 19:16
Show Gist options
  • Save kenjitagawa/7e3c39bc8179f8e37174c0b9b000e036 to your computer and use it in GitHub Desktop.
Save kenjitagawa/7e3c39bc8179f8e37174c0b9b000e036 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