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 {