-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileutils.go
47 lines (37 loc) · 907 Bytes
/
fileutils.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
45
46
47
package main
import (
"fmt"
"path/filepath"
"os"
)
func PathExists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil { return true, nil }
if os.IsNotExist(err) { return false, nil }
return false, err
}
func GetFullDirPath(dir string) string {
return GetRootDir() + dir
}
func GetFullFilePath(dir, fileName string) string {
return GetRootDir() + dir + string(filepath.Separator) + fileName
}
func CreateDir(fullDirPath string) {
os.Mkdir(fullDirPath, 0777)
}
func GetRootDir() string {
return "." + string(filepath.Separator)
}
func CreateFile(fullFilePath string) *os.File {
f, err := os.Create(fullFilePath)
if err != nil {
panic(err)
}
return f
}
func WriteFile(f *os.File, content string, fullFilePath string) {
fmt.Fprintln(f, content)
}
func CloseFile(f *os.File, fullFilePath string) {
f.Close()
}