9951 explained code solutions for 126 technologies

golangHow to check if file exist

package main

import (

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

default package declaration


include operating-system level library

func main() {

declare main function that will be launched automatically


retrieve file stats

err == nil

if no error raised - file exists