Standard library / os
os.IsExist()
Legacy existence-error predicate; prefer errors.Is with os.ErrExist for wrapped errors. Example uses a disposable temporary workspace. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func IsExist(err error) boolParameters & Attributes
| Name | Type | Description |
|---|---|---|
| err | error | Error to classify. |
Return Value
bool
Legacy existence-error predicate; prefer errors.Is with os.ErrExist for wrapped errors.
Working Example
Example Snippetgo
package main
import ( "fmt" "os")
func check(e error) { if e != nil { panic(e) }}func seed() { check(os.WriteFile("a.txt", []byte("abc"), 0600)) }func workspace() func() { root, e := os.MkdirTemp("", "bytemind-go-") check(e) old, e := os.Getwd() check(e) check(os.Chdir(root)) return func() { check(os.Chdir(old)); check(os.RemoveAll(root)) }}func main() { defer workspace()(); seed(); e := os.Mkdir("a.txt", 0700); fmt.Println(os.IsExist(e)) }