Skip to content

Instantly share code, notes, and snippets.

@mattes
Last active May 3, 2024 22:20
Show Gist options
  • Save mattes/d13e273314c3b3ade33f to your computer and use it in GitHub Desktop.
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
}
@yangyongzhi7
Copy link

Thanks

@lukemilby
Copy link

I was here.

Thanks

@magicwarms
Copy link

Thanks!

@BloodmageThalnos
Copy link

shanks!

@stricklandye
Copy link

haha, although it is trivial still helps a lot ,thanks!

@mayooot
Copy link

mayooot commented Feb 19, 2024

Thanks

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