Skip to content

Commit

Permalink
Check if file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
yanhao-pro committed Nov 15, 2022
1 parent c14231b commit d7b6ef4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions snippets/go.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,12 @@ snippet signals "handle signals"
fmt.Println("awaiting signal")
<-done
fmt.Println("exiting")

snippet fileExists "check if a file exists"
if _, err := os.Stat("${1}"); err == nil {
// path/to/whatever exists
} else if errors.Is(err, os.ErrNotExist) {
// path/to/whatever does *not* exist
} else {
// other errors
}

0 comments on commit d7b6ef4

Please sign in to comment.