Skip to content

Instantly share code, notes, and snippets.

@mattes
Last active October 11, 2024 16:22
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
}
@KEINOS
Copy link

KEINOS commented Mar 21, 2021

Great! It was so helpful! 👍

@ondrejsika
Copy link

Thanks 👍

@gowizzard
Copy link

Thanks

@9cat
Copy link

9cat commented Apr 27, 2022

that helps~

@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