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: [2018-08-22 https://github.com/karrick/godirwalk/blob/master/README.md ]

Golang

Compile and Run

String

Types and Values

Branching and Loop

Data Structure

Function

Misc

Examples

Reference