package main
import (
"fmt"
"os"
)
func main() {
f := "D:\\cron"
fmt.Println(os.Stat(f))
fmt.Println(os.Open(f))
f = "D:\\con"
fmt.Println(os.Stat(f))
fmt.Println(os.Open(f))
}
result:
<nil> CreateFile D:\cron: The system cannot find the file specified.
<nil> open D:\cron: The system cannot find the file specified.
<nil> CreateFile D:\con: The parameter is incorrect.
&{0xc000086a00} <nil>
I think when the file doesn't exist,os.Open should return err != nil
But I wonder why "D:\con" returns err == nil
Are you using Windows by any chance? "con" is a reserved file name, a relic of the DOS days.