-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
56 lines (52 loc) · 1.26 KB
/
util.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
50
51
52
53
54
55
56
package main
import (
"fmt"
"io"
"math"
"os"
)
func checkDestDir(path string) bool {
s, err := os.Stat(path)
if err != nil {
if os.IsNotExist(err) {
err := os.MkdirAll(path, os.ModePerm)
if err != nil {
fmt.Println("无法创建目标目录", path)
return false
}
return true
}
fmt.Println(path, "目录存在异常,请删除这个文件夹,重新创建一下。")
return false
}
if s.IsDir() {
f, err := os.Open(path)
if err != nil {
fmt.Println(path, "目录存在异常,请删除这个文件夹,重新创建一下。")
return false
}
_, err = f.Readdir(1)
if err == io.EOF {
return true
}
fmt.Println(path, "目录是一个非空目录,请重新指定")
return false
}
fmt.Println("存在一个文件名是", path, "的文件,请删除它或保存到其他地方")
return false
}
var preNumber = []int64{9, 99, 999, 9999, 99999, 999999, 9999999, 99999999, 999999999, 9999999999, 99999999999, 999999999999, 9999999999999, 99999999999999, 999999999999999, 9999999999999999, 99999999999999999, 999999999999999999}
func getNumWidth(num int64) int {
if num == math.MinInt64 {
return 19
}
if num < 0 {
num = -num
}
for i := 0; i < 18; i++ {
if num <= preNumber[i] {
return i + 1
}
}
return 19
}