From b69e45e10fc03853832ff4245d38239d6d75a1e2 Mon Sep 17 00:00:00 2001 From: "rick.chan" Date: Fri, 1 Sep 2023 14:35:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=A4=BA=E4=BE=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: rick.chan --- .../Language/Go/Basic/File/Gloang_文件操作.md | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) 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