-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
44 lines (38 loc) · 933 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"os"
"fmt"
)
func IsExistFile(path string) bool {
if _, err := os.Stat(path); os.IsNotExist(err) {
return false
}
return true
}
func CreateDirectory(path string) error {
if a, err := os.Stat(path); err != nil || !a.IsDir() {
return os.Mkdir(path, os.ModePerm)
}
return nil
}
func createFolderIfNotExists(folderPath string) error {
if _, err := os.Stat(folderPath); os.IsNotExist(err) {
err = os.MkdirAll(folderPath, 0755)
if err != nil {
return err
}
fmt.Printf("文件夹 %s 不存在,已成功创建!\n", folderPath)
} else {
fmt.Printf("文件夹 %s 已存在。\n", folderPath)
}
return nil
}
func CreateFileIfNotExist(file string) {
_, err := os.Stat(file)
if err != nil {
if os.IsNotExist(err) {
os.Create(file)
fmt.Printf("文件 %s 不存在,已成功创建!\n", file)
}
}
}