Golang: Check File Exist

By Xah Lee. Date: .
package main

import "fmt"
import "os"

// fileExist. check if a file exist
func fileExist(path string) bool {
	_, err := os.Stat(path)
	if err == nil {
		return true
	}
	return false
}

func main() {
	fmt.Printf("%v\n", fileExist("/Users/x/xyz.txt"))
}

here's alternative: https://github.com/karrick/godirwalk/blob/master/README.md

Golang

Examples

Reference