// 等价于Python's if not os.path.exists(filename) if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) { // path/to/whatever does not exist } // 等价于Python's if os.path.exists(filename) if _, err := os.Stat("/path/to/whatever"); err == nil { // path/to/whatever exists } // 删除文件 func Remove(name string) error Remove removes the named file or directory. If there is an error, it will be of type *PathError. err := os.remove("./test.txt") if err != nil { return }
参考链接:Python-Golang-文件是否存在