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
993 B
47 lines
993 B
package utils
|
|
|
|
import (
|
|
"gin-vue-admin/global"
|
|
"go.uber.org/zap"
|
|
"os"
|
|
)
|
|
|
|
// @title PathExists
|
|
// @description 文件目录是否存在
|
|
// @auth (2020/04/05 20:22)
|
|
// @param path string
|
|
// @return err 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
|
|
}
|
|
|
|
// @title createDir
|
|
// @description 批量创建文件夹
|
|
// @auth (2020/04/05 20:22)
|
|
// @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
|
|
}
|