-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.go
49 lines (44 loc) · 865 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
45
46
47
48
49
package main
import (
"bytes"
"io/ioutil"
"os"
)
func FileExistBool(filename string) bool {
_, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return true
}
func FolderExistBool(folder string) bool {
_, err := ioutil.ReadDir(folder)
if err != nil {
return false
}
return true
}
func FileReWriteByte(filename string, b []byte) error {
err := ioutil.WriteFile(filename, b, 0644)
if err != nil {
return err
}
return nil
}
//FileCompareByteBool
/*
function compare file content and byte content
return true if b equal filename content
return false if b not equal filename content or error
*/
func FileCompareByteBool(filename string, b []byte) (bool, error) {
dat, err := ioutil.ReadFile(filename)
if err != nil {
return false, err
}
res := bytes.Compare(dat, b)
if res == 0 {
return true, nil
}
return false, nil
}