MCPcopy Create free account
hub / github.com/OpenAtomFoundation/SmartIDE / IsExist

Function IsExist

cli/pkg/common/path.go:29–48  ·  view source on GitHub ↗

判断所给路径文件/文件夹是否存在

(path string)

Source from the content-addressed store, hash-verified

27
28// 判断所给路径文件/文件夹是否存在
29func 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// 判断所给路径是否为文件夹
51func IsDir(path string) bool {

Callers 3

DownloadFilesByGitMethod · 0.85
writeToFileFunction · 0.85

Calls 1

JoinMethod · 0.45

Tested by

no test coverage detected