diff --git a/Software/Development/Language/Go/Basic/File/Gloang_文件操作.md b/Software/Development/Language/Go/Basic/File/Gloang_文件操作.md index d5533be..c732046 100644 --- a/Software/Development/Language/Go/Basic/File/Gloang_文件操作.md +++ b/Software/Development/Language/Go/Basic/File/Gloang_文件操作.md @@ -26,22 +26,32 @@ func IsDir(name string) bool { } ``` -## 检查文件是否存在 +## 检查文件(包括文件夹)是否存在 ```go func IsPathExist(path string) bool { _, e := os.Stat(path) if e != nil { - if os.IsExist(e) { - return true - } else { - return false - } + return os.IsExist(e) } return true } ``` +## 检查文件(不包括文件夹)是否存在 + +```go +func isFileExist(filename string) bool { + info, e := os.Stat(filename) + + if e == nil { + return !info.IsDir() + } else { + return os.IsExist(e) + } +} +``` + ## 创建文件夹(如果文件夹不存在则创建) ```go