Skip to content

Instantly share code, notes, and snippets.

@mattes
Last active February 11, 2026 19:47
Show Gist options
  • Select an option

  • Save mattes/d13e273314c3b3ade33f to your computer and use it in GitHub Desktop.

Select an option

Save mattes/d13e273314c3b3ade33f 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
}
@Anhdao153
Copy link

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment