Skip to content

Instantly share code, notes, and snippets.

@jdx
Last active August 29, 2015 14:20
Show Gist options
  • Save jdx/6dfd1c95a02beb6bb126 to your computer and use it in GitHub Desktop.
Save jdx/6dfd1c95a02beb6bb126 to your computer and use it in GitHub Desktop.
func fileExists(path string) (bool, error) {
var err error
if runtime.GOOS == "windows" {
// Windows doesn't seem to like using os.Stat
_, err = os.Open(path)
} else {
_, err = os.Stat(path)
}
if err != nil {
if os.IsNotExist(err) {
return false, nil
}
return false, err
}
return true, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment