Add FileExist function
This commit is contained in:
parent
388ba638bd
commit
3ee1062f71
1 changed files with 17 additions and 0 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue