package main import ( "bufio" "fmt" "os" ) // https://golangr.com/file-exists func main() { if len(os.Args) < 2 { fmt.Println("Not enough arguments") os.Exit(1) } for i := 1; i < len(os.Args); i++ { if _, err := os.Stat(os.Args[i]); err == nil { reader(os.Args[i]) } else { fmt.Printf("File does not exist\n") } } } func reader(file string) { fil, err := os.Open(file) if err != nil { panic(err) } defer fil.Close() scanner := bufio.NewScanner(fil) for scanner.Scan() { fmt.Println(scanner.Text()) } if err := scanner.Err(); err != nil { fmt.Println(err) } }