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
1.1 KiB

  1. package utils
  2. import "os"
  3. // @title PathExists
  4. // @description 文件目录是否存在
  5. // @auth (2020/04/05 20:22)
  6. // @param path string
  7. // @return err error
  8. func PathExists(path string) (bool, error) {
  9. _, err := os.Stat(path)
  10. if err == nil {
  11. return true, nil
  12. }
  13. if os.IsNotExist(err) {
  14. return false, nil
  15. }
  16. return false, err
  17. }
  18. // @title createDir
  19. // @description 批量创建文件夹
  20. // @auth (2020/04/05 20:22)
  21. // @param dirs string
  22. // @return err error
  23. func CreateDir(dirs ...string) (err error) {
  24. for _, v := range dirs {
  25. exist, err := PathExists(v)
  26. if err != nil {
  27. //log.L.Info(fmt.Sprintf("get dir error![%v]\n", err))
  28. return err
  29. }
  30. if exist {
  31. //log.L.Info(fmt.Sprintf("has dir![%v]\n"+_dir))
  32. } else {
  33. //log.L.Info(fmt.Sprintf("no dir![%v]\n"+_dir))
  34. // 创建文件夹
  35. err = os.Mkdir(v, os.ModePerm)
  36. if err != nil {
  37. //log.L.Error(fmt.Sprintf("mkdir error![%v]\n",err))
  38. } else {
  39. //log.L.Info("mkdir success!\n")
  40. }
  41. }
  42. }
  43. return err
  44. }