Skip to content

Commit 42bd263

Browse files
authored
added file exists fn
1 parent db582d3 commit 42bd263

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

utils/file/file.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@ func WriteToFile(s []byte, file string) {
99
//
1010
f, err := os.Create(file)
1111
if err != nil {
12-
//slack.Bug("WriteToFile", err.Error())
1312
log.Fatal(err)
1413
}
1514
f.Write(s)
1615
defer f.Close()
1716
}
17+
18+
// FileExists checks if a file exists and is not a directory.
19+
func FileExists(path string) bool {
20+
info, err := os.Stat(path)
21+
if os.IsNotExist(err) {
22+
return false
23+
}
24+
return !info.IsDir()
25+
}

0 commit comments

Comments
 (0)