Q:

check if file exists golang

if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) {
  // path/to/whatever does not exist
}
0
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()
}
0

New to Communities?

Join the community