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
943 B

  1. package utils
  2. import (
  3. "gin-vue-admin/global"
  4. "go.uber.org/zap"
  5. "os"
  6. )
  7. //@author: [piexlmax](https://github.com/piexlmax)
  8. //@function: PathExists
  9. //@description: 文件目录是否存在
  10. //@param: path string
  11. //@return: bool, error
  12. func PathExists(path string) (bool, error) {
  13. _, err := os.Stat(path)
  14. if err == nil {
  15. return true, nil
  16. }
  17. if os.IsNotExist(err) {
  18. return false, nil
  19. }
  20. return false, err
  21. }
  22. //@author: [piexlmax](https://github.com/piexlmax)
  23. //@function: CreateDir
  24. //@description: 批量创建文件夹
  25. //@param: dirs ...string
  26. //@return: err error
  27. func CreateDir(dirs ...string) (err error) {
  28. for _, v := range dirs {
  29. exist, err := PathExists(v)
  30. if err != nil {
  31. return err
  32. }
  33. if !exist {
  34. global.GVA_LOG.Debug("create directory" + v)
  35. if err := os.MkdirAll(v, os.ModePerm); err != nil {
  36. global.GVA_LOG.Error("create directory"+v, zap.Any(" error:", err))
  37. return err
  38. }
  39. }
  40. }
  41. return err
  42. }