Add FileExist function

This commit is contained in:
HikariKnight 2023-04-09 16:59:51 +02:00
parent 388ba638bd
commit 3ee1062f71

View file

@ -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
}