附近小店
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.

file_and_dir.go 502 B

3 months ago
1234567891011121314151617181920212223242526272829
  1. package utils
  2. import "os"
  3. // 判断所给路径文件、文件夹是否存在
  4. func Exists(path string) bool {
  5. _, err := os.Stat(path) //os.Stat获取文件信息
  6. if err != nil {
  7. if os.IsExist(err) {
  8. return true
  9. }
  10. return false
  11. }
  12. return true
  13. }
  14. // 判断所给路径是否为文件夹
  15. func IsDir(path string) bool {
  16. s, err := os.Stat(path)
  17. if err != nil {
  18. return false
  19. }
  20. return s.IsDir()
  21. }
  22. // 判断所给路径是否为文件
  23. func IsFile(path string) bool {
  24. return !IsDir(path)
  25. }