From 3ee1062f71137e9f4af95f50182ce80961f7f7b8 Mon Sep 17 00:00:00 2001 From: HikariKnight <2557889+HikariKnight@users.noreply.github.com> Date: Sun, 9 Apr 2023 16:59:51 +0200 Subject: [PATCH] Add FileExist function --- pkg/fileio/fileio.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/fileio/fileio.go b/pkg/fileio/fileio.go index 4a24a47..959394e 100644 --- a/pkg/fileio/fileio.go +++ b/pkg/fileio/fileio.go @@ -2,6 +2,7 @@ package fileio import ( "bufio" + "errors" "fmt" "os" @@ -49,3 +50,19 @@ func ReadFile(fileName string) string { return string(content) } + +func FileExist(fileName string) bool { + var exist bool + + // Check if the file exists + if _, err := os.Stat(fileName); !errors.Is(err, os.ErrNotExist) { + // Set the value to true + exist = true + } else { + // Set the value to false + exist = false + } + + // Return if the file exists + return exist +}