From a9e63b2fec63b73e5578b25579d78adf85a80e05 Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Fri, 25 Aug 2023 11:25:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=96=87=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/utils/file.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/utils/file.go b/core/utils/file.go index 3176ff4..059f13d 100644 --- a/core/utils/file.go +++ b/core/utils/file.go @@ -8,8 +8,11 @@ import ( "omc/handle/model" "os" "path" + "path/filepath" "strings" "time" + + "github.com/aceld/zinx/zlog" ) //BJ/HX/RJ/OMC/FM/告警文件生成时间 @@ -42,6 +45,15 @@ func FileName(meta *FileNameMeta) string { } func CreateFile(filePath string, data []model.OmcAlarm) error { + // 获取文件所在的目录路径 + dirPath := filepath.Dir(filePath) + + // 确保文件夹路径存在 + err := os.MkdirAll(dirPath, os.ModePerm) + if err != nil { + zlog.Ins().ErrorF("创建文件夹失败 CreateFile %v", err) + } + // 创建或打开文件 file, err := os.Create(filePath) if err != nil {