9951 explained code solutions for 126 technologies


golangHow to check if file exist


package main

import (
  "fmt"
	"os"
)

func main() {
  if _, err := os.Stat("/etc/passwd"); err == nil {
    fmt.Println("file is there!")
  }
}ctrl + c
package main

default package declaration

"os"

include operating-system level library

func main() {

declare main function that will be launched automatically

os.Stat

retrieve file stats

err == nil

if no error raised - file exists