RosettaCodeData/Task/Check-that-file-exists/Go/check-that-file-exists.go
2023-07-01 13:44:08 -04:00

24 lines
388 B
Go

package main
import (
"fmt"
"os"
)
func printStat(p string) {
switch i, err := os.Stat(p); {
case err != nil:
fmt.Println(err)
case i.IsDir():
fmt.Println(p, "is a directory")
default:
fmt.Println(p, "is a file")
}
}
func main() {
printStat("input.txt")
printStat("/input.txt")
printStat("docs")
printStat("/docs")
}