| 123456789101112131415161718192021222324252627282930 |
- package file
- import (
- "os"
- "path/filepath"
- cerror "github.com/cherry-game/cherry/error"
- cfile "github.com/cherry-game/cherry/extend/file"
- )
- // 创建目录
- func CreateDir(filePath string) error {
- if !cfile.IsDir(filePath) {
- if err := os.MkdirAll(filePath, 0755); err != nil {
- return cerror.Errorf("Create dir error. filePath = %s, err = %v", filePath, err)
- }
- }
- return nil
- }
- // 写文件
- func Write(filePath string, fileName string, data []byte) error {
- fullFilePath := filepath.Join(filePath, fileName)
- if err := os.WriteFile(fullFilePath, data, 0644); err != nil {
- return cerror.Errorf("Write file error. fullFilePath = %s, err = %v", fullFilePath, err)
- }
- return nil
- }
|