Skip to content

Instantly share code, notes, and snippets.

@wendal
Last active April 1, 2020 13:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wendal/3930261 to your computer and use it in GitHub Desktop.
Save wendal/3930261 to your computer and use it in GitHub Desktop.
golang判断文件是否存在
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
}
@CNSumi
Copy link

CNSumi commented Mar 15, 2018

good

@elvisNg
Copy link

elvisNg commented Aug 13, 2018

若同一个路径 重复调用判断文件是否存在的方法 然后就算把文件删除了,以然会返回同一个地址的error 然后依然判断文件是存在的。
输出内存地址是一样的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment