forked from go/golangs_learn
viviman
3 years ago
4 changed files with 132 additions and 1 deletions
@ -0,0 +1,20 @@ |
|||
package go_to_dir |
|||
|
|||
import ( |
|||
"fmt" |
|||
//"io/ioutil"
|
|||
//"log"
|
|||
"os" |
|||
"path/filepath" |
|||
) |
|||
|
|||
func main() { |
|||
pwd, _ := os.Getwd() |
|||
|
|||
//获取当前目录下的所有文件或目录信息
|
|||
filepath.Walk(pwd, func(path string, info os.FileInfo, err error) error { |
|||
fmt.Println(path) //打印path信息
|
|||
fmt.Println(info.Name()) //打印文件或目录名
|
|||
return nil |
|||
}) |
|||
} |
@ -0,0 +1,21 @@ |
|||
package go_to_dir |
|||
|
|||
|
|||
import ( |
|||
"fmt" |
|||
"io/ioutil" |
|||
"log" |
|||
"os" |
|||
) |
|||
func main() { |
|||
pwd, _ := os.Getwd() |
|||
//获取文件或目录相关信息
|
|||
fileInfoList, err := ioutil.ReadDir(pwd) |
|||
if err != nil { |
|||
log.Fatal(err) |
|||
} |
|||
fmt.Println(len(fileInfoList)) |
|||
for i := range fileInfoList { |
|||
fmt.Println(fileInfoList[i].Name()) //打印当前文件或目录下的文件或目录名
|
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
package go_to_dir |
|||
|
|||
import ( |
|||
"fmt" |
|||
//"io/ioutil"
|
|||
"log" |
|||
"os" |
|||
"path/filepath" |
|||
) |
|||
|
|||
func main() { |
|||
pwd, _ := os.Getwd() |
|||
|
|||
//获取当前目录下的文件或目录名(包含路径)
|
|||
filepathNames, err := filepath.Glob(filepath.Join(pwd, "*")) |
|||
if err != nil { |
|||
log.Fatal(err) |
|||
} |
|||
|
|||
for i := range filepathNames { |
|||
fmt.Println(filepathNames[i]) //打印path
|
|||
} |
|||
|
|||
} |
@ -1,12 +1,78 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"io/ioutil" |
|||
"log" |
|||
"os" |
|||
"strings" |
|||
"time" |
|||
) |
|||
|
|||
/* |
|||
思路: 脚本按照顺序拼接,旧文件按照 utf8 格式清空 |
|||
|
|||
*/ |
|||
import () |
|||
|
|||
var splitStr = "/* 202" |
|||
|
|||
var endName = ".sql" |
|||
var endFileName string |
|||
var History = "/history/" |
|||
var DBStr = []string{"/MYSQL/update", "/ORACLE/update", "/SHENTONG/update", "/DM/update", "/KingBase/update"} |
|||
var mapStr = make(map[string]string) |
|||
var mapInt = make(map[int8]string) |
|||
|
|||
//存在所有对象信息 - 集合
|
|||
func main() { |
|||
// Todo 合并的SQL文件名称,超过1000行,分割多个文件
|
|||
endFileName = History + time.Now().Format("20060102") + endName |
|||
|
|||
// aaa := os.Args //当前目录数组
|
|||
var aaa string = "/Users/zhangxianwei/IDEA/hy_sql" |
|||
for i := range DBStr { |
|||
kkk := aaa + DBStr[i] |
|||
getAllFile(kkk) |
|||
} |
|||
|
|||
for s := range mapStr { |
|||
log.Println(s, mapStr[s]) |
|||
} |
|||
} |
|||
|
|||
func getAllFile(pwd string) { |
|||
//获取文件或目录相关信息
|
|||
fileInfoList, err := ioutil.ReadDir(pwd) |
|||
if err != nil { |
|||
log.Fatal(err) |
|||
} |
|||
|
|||
for i := range fileInfoList { |
|||
if strings.HasSuffix(fileInfoList[i].Name(), endName) { |
|||
path := pwd + "/" + fileInfoList[i].Name() |
|||
s := read(path) |
|||
split := strings.Split(s, splitStr) |
|||
|
|||
for i2 := range split { |
|||
// log.Println(split[i2], "\n")
|
|||
mapStr[path] = s |
|||
s2 := split[i2] |
|||
log.Println(s2) |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
func read(path string) string { |
|||
f, _ := os.Open(path) |
|||
all, _ := ioutil.ReadAll(f) |
|||
return string(all) |
|||
} |
|||
|
|||
/** |
|||
write 输出到文件 |
|||
*/ |
|||
func write(s, path string) { |
|||
file3, _ := os.Create(path) |
|||
file3.WriteString(s) |
|||
file3.Close() |
|||
} |
|||
|
Loading…
Reference in new issue