You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
930 B
47 lines
930 B
package utils
|
|
|
|
import (
|
|
"gin-vue-admin/global"
|
|
"go.uber.org/zap"
|
|
"os"
|
|
)
|
|
|
|
//@author: [piexlmax](https://github.com/piexlmax)
|
|
//@function: PathExists
|
|
//@description: 文件目录是否存在
|
|
//@param: path string
|
|
//@return: bool, error
|
|
|
|
func PathExists(path string) (bool, error) {
|
|
_, err := os.Stat(path)
|
|
if err == nil {
|
|
return true, nil
|
|
}
|
|
if os.IsNotExist(err) {
|
|
return false, nil
|
|
}
|
|
return false, err
|
|
}
|
|
|
|
//@author: [piexlmax](https://github.com/piexlmax)
|
|
//@function: CreateDir
|
|
//@description: 批量创建文件夹
|
|
//@param: dirs ...string
|
|
//@return: err error
|
|
|
|
func CreateDir(dirs ...string) (err error) {
|
|
for _, v := range dirs {
|
|
exist, err := PathExists(v)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !exist {
|
|
global.GVA_LOG.Debug("create directory" + v)
|
|
err = os.MkdirAll(v, os.ModePerm)
|
|
if err != nil {
|
|
global.GVA_LOG.Error("create directory"+ v, zap.Any(" error:", err))
|
|
}
|
|
}
|
|
}
|
|
return err
|
|
}
|