创建文件夹

This commit is contained in:
TsMask
2023-08-25 11:25:24 +08:00
parent de3d898717
commit a9e63b2fec

View File

@@ -8,8 +8,11 @@ import (
"omc/handle/model" "omc/handle/model"
"os" "os"
"path" "path"
"path/filepath"
"strings" "strings"
"time" "time"
"github.com/aceld/zinx/zlog"
) )
//BJ/HX/RJ/OMC/FM/告警文件生成时间 //BJ/HX/RJ/OMC/FM/告警文件生成时间
@@ -42,6 +45,15 @@ func FileName(meta *FileNameMeta) string {
} }
func CreateFile(filePath string, data []model.OmcAlarm) error { 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) file, err := os.Create(filePath)
if err != nil { if err != nil {