-
Notifications
You must be signed in to change notification settings - Fork 0
/
autocode_test.go
47 lines (43 loc) · 953 Bytes
/
autocode_test.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 autocode
import (
"io/ioutil"
"os"
"strings"
"testing"
)
func TestDemo(t *testing.T) {
InitDB("root", "123456", "localhost", "3306", "sale")
a := ProBasic{Name: "Product", TblName: "tbl_product", Path: ".", ModName: "testimpl"}
a.Start()
}
func TestChangeSuffix(t *testing.T) {
dir := `./template`
// findDir(dir, ".go")
findDir(dir, ".tpl")
}
// 遍历的文件夹
func findDir(dir, suffix string) {
files, err := ioutil.ReadDir(dir)
if err != nil {
panic(err)
}
path := dir + `/`
// 遍历这个文件夹
for _, f := range files {
// 判断是不是目录
if f.IsDir() {
findDir(path+f.Name(), suffix)
} else {
oldPath := path + f.Name()
if !(strings.Contains(oldPath, ".go") || strings.Contains(oldPath, ".tpl")) {
continue
}
newPath := path + f.Name()[:strings.LastIndex(f.Name(), ".")] + suffix
err := os.Rename(oldPath, newPath)
if err != nil {
println(err)
break
}
}
}
}