判断所给路径文件/文件夹是否存在
(path string)
| 27 | |
| 28 | // 判断所给路径文件/文件夹是否存在 |
| 29 | func IsExist(path string) bool { |
| 30 | if strings.TrimSpace(path) == "" { |
| 31 | return false |
| 32 | } |
| 33 | |
| 34 | // 替换当前用户目录 |
| 35 | if path[0] == '~' { |
| 36 | home, _ := os.UserHomeDir() |
| 37 | if home != "" { |
| 38 | path = filepath.Join(home, path[1:]) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // 检测是否存在 |
| 43 | _, err := os.Stat(path) //os.Stat获取文件信息 |
| 44 | if err != nil && errors.Is(err, os.ErrNotExist) { |
| 45 | return false |
| 46 | } |
| 47 | return true |
| 48 | } |
| 49 | |
| 50 | // 判断所给路径是否为文件夹 |
| 51 | func IsDir(path string) bool { |
no test coverage detected