Last active
April 1, 2020 13:05
-
-
Save wendal/3930261 to your computer and use it in GitHub Desktop.
golang判断文件是否存在
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func PathExist(_path string) bool { | |
_, err := os.Stat(_path) | |
if err != nil && err.Error() == os.ErrNotExist.Error() { | |
return false | |
} | |
return true | |
} | |
// golang新版本的应该 | |
func PathExist(_path string) bool { | |
_, err := os.Stat(_path) | |
if err != nil && os.IsNotExist(err) { | |
return false | |
} | |
return true | |
} |
若同一个路径 重复调用判断文件是否存在的方法 然后就算把文件删除了,以然会返回同一个地址的error 然后依然判断文件是存在的。
输出内存地址是一样的
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good