Answers for "go if file exists"

Go
0

go if file exists

import "os"

func main() {
	if functs.FileExists("path/to/file") {
		fmt.Println("Example file found.")
	} else {
		fmt.Println("Example file not found!")
	}
}

func FileExists(filename string) bool {
	info, err := os.Stat(filename)
	if os.IsNotExist(err) {
		return false
	}
	return !info.IsDir()
}
Posted by: Guest on July-28-2020

Browse Popular Code Answers by Language