개요
- Go FileExists()
package main
import (
"fmt"
"os"
)
func fileExists(filename string) bool {
info, err := os.Stat(filename)
return err == nil && !info.IsDir()
}
func main() {
// true
fmt.Println(fileExists("/etc/services")) // File Exists
// false
fmt.Println(fileExists("/etc/file-not-exists")) // File Not Exists
fmt.Println(fileExists("/etc")) // Directory Exists
}