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

  1. package utils
  2. import (
  3. "gin-vue-admin/global"
  4. "go.uber.org/zap"
  5. "os"
  6. )
  7. // @title PathExists
  8. // @description 文件目录是否存在
  9. // @auth (2020/04/05 20:22)
  10. // @param path string
  11. // @return err 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. // @title createDir
  23. // @description 批量创建文件夹
  24. // @auth (2020/04/05 20:22)
  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. err = os.MkdirAll(v, os.ModePerm)
  36. if err != nil {
  37. global.GVA_LOG.Error("create directory"+ v, zap.Any(" error:", err))
  38. }
  39. }
  40. }
  41. return err
  42. }