This article describes the method of detecting whether a go language file exists. Share it for your reference. The specific analysis is as follows:
Go language to check whether the file exists. First create a FileInfo. If there is no error, then check whether it is a directory through IsDir().
Copy the codeThe code is as follows:
finfo, err := ("")
if err != nil {
// no such file or dir
return
}
if () {
// it's a file
} else {
// it's a directory
}
if err != nil {
// no such file or dir
return
}
if () {
// it's a file
} else {
// it's a directory
}
I hope this article will be helpful to everyone's Go language programming.