From dac0c7f54085779a490205ffa817ec19bc094f4f Mon Sep 17 00:00:00 2001 From: VIVIMAN Date: Mon, 6 Mar 2023 15:24:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=83=A8=E5=88=86=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...下文件夹,文件向上移动两层.go | 17 ++++-- .../data_func/go_to_dir/readDir/main.go | 10 ++++ ...下文件夹,文件向上移动两层.go | 56 ++++++++++--------- 3 files changed, 53 insertions(+), 30 deletions(-) create mode 100644 golang_learn/data_func/go_to_dir/readDir/main.go diff --git a/golang_learn/data_func/go_to_dir/readDir/linux读取指定目录下文件夹,文件向上移动两层.go b/golang_learn/data_func/go_to_dir/readDir/linux读取指定目录下文件夹,文件向上移动两层.go index c15eb68..4aac251 100644 --- a/golang_learn/data_func/go_to_dir/readDir/linux读取指定目录下文件夹,文件向上移动两层.go +++ b/golang_learn/data_func/go_to_dir/readDir/linux读取指定目录下文件夹,文件向上移动两层.go @@ -13,7 +13,7 @@ func main() { del := "rm -rf ./unzip" fmt.Printf("执行命令:%s\n", del) cmd := exec.Command(del) - _ = cmd.Run() + _ = cmd.Start() // 执行解压操作,固定死目录和文件名称 // drc:drc jth:jth 同目录下存在 unzip 目录(用于解压文件) @@ -25,12 +25,12 @@ func main() { "%s/jth.jth unzip %s/1.hzb %s/unzip %s/unzip/Photos Z93z4H5b6z7d35b8", a, a, a, a, a, a, a, a) fmt.Printf("执行命令:%s\n", shellUnzip) cmd = exec.Command(shellUnzip) - _ = cmd.Run() + _ = cmd.Start() mvPhotos, all := fmt.Sprintf("cd %s/unzip/Photos", a), "" fmt.Printf("执行命令:%s\n", mvPhotos) cmd = exec.Command(mvPhotos) - _ = cmd.Run() + _ = cmd.Start() for _, i := range f { for _, i2 := range f { all += fmt.Sprintf("cd %s/%s/ && mv * ../ && ", i, i2) @@ -40,13 +40,20 @@ func main() { all += "ls" fmt.Printf("执行命令:%s\n", all) cmd = exec.Command(all) - _ = cmd.Run() + _ = cmd.Start() // 生成压缩包 zipFile := fmt.Sprintf("7z a 1.zip %s/unzip/", a) fmt.Printf("执行命令:%s\n", zipFile) cmd = exec.Command(zipFile) - _ = cmd.Run() + err := cmd.Start() + linuxError(err) } var f = []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"} + +func linuxError(e error) { + if e != nil { + fmt.Println(e) + } +} diff --git a/golang_learn/data_func/go_to_dir/readDir/main.go b/golang_learn/data_func/go_to_dir/readDir/main.go new file mode 100644 index 0000000..586fb1b --- /dev/null +++ b/golang_learn/data_func/go_to_dir/readDir/main.go @@ -0,0 +1,10 @@ +package main + +import ( + "os" +) + +func main() { + _ = os.Mkdir("./unzip", os.ModePerm) + _ = os.Mkdir("./unzip/Photos", os.ModePerm) +} diff --git a/golang_learn/data_func/go_to_dir/readDir/windows读取指定目录下文件夹,文件向上移动两层.go b/golang_learn/data_func/go_to_dir/readDir/windows读取指定目录下文件夹,文件向上移动两层.go index b24091b..df115bf 100644 --- a/golang_learn/data_func/go_to_dir/readDir/windows读取指定目录下文件夹,文件向上移动两层.go +++ b/golang_learn/data_func/go_to_dir/readDir/windows读取指定目录下文件夹,文件向上移动两层.go @@ -2,49 +2,55 @@ package main import ( "fmt" + "os" "os/exec" + "path" "path/filepath" ) func main() { a, _ := filepath.Abs("./") - fmt.Printf("当前目录:%s\n", a) + fmt.Printf("当前目录:%s \n开始执行...\n", a) a = "E:/" - del := "del /S/Q unzip\\*.*" - fmt.Printf("执行命令:%s\n", del) - cmd := exec.Command(del) - _ = cmd.Run() + // 删除目录 + winError(os.RemoveAll(path.Join([]string{a, "unzip"}...))) + + // 新建目录 + winError(os.Mkdir(a+"/unzip", os.ModePerm)) + winError(os.Mkdir(a+"/unzip/Photos", os.ModePerm)) + winError(os.Mkdir(a+"/unzip/Table", os.ModePerm)) // 执行解压操作,固定死目录和文件名称 // drc:drc jth:jth 同目录下存在 unzip 目录(用于解压文件) - shellUnzip := fmt.Sprintf("cd %s && "+ - "set Hy7zEncryptPath=%s/drc.drc && "+ - "set Hy7zJarPath=%s/jth.jth && "+ - "set Hy7zLogFileName=%s/hy_7z.log && "+ - "D:\\hzb2022\\tomcat8\\JDK1.8\\jre\\bin\\java -jar -Xms512m -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=512M "+ - "%s/jth.jth unzip %s/1.hzb %s/unzip %s/unzip/Photos Z93z4H5b6z7d35b8", a, a, a, a, a, a, a, a) - fmt.Printf("执行命令:%s\n", shellUnzip) - cmd = exec.Command(shellUnzip) - _ = cmd.Run() - - mvPhotos, all := fmt.Sprintf("%s/unzip/Photos", a), "" + winError(exec.Command("cd " + a).Start()) + winError(exec.Command("set Hy7zEncryptPath=" + a + "/drc.drc").Start()) + winError(exec.Command("set Hy7zJarPath=" + a + "/jth.jth").Start()) + winError(exec.Command("set Hy7zLogFileName=" + a + "/hy_7z.log").Start()) + winError(exec.Command(a + "/jre/bin/java -jar -Xms512m -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=512M " + + a + "/jth.jth unzip " + a + "/1.hzb " + a + "/unzip " + a + "/unzip/Photos Z93z4H5b6z7d35b8").Start()) + for _, i := range e { for _, i2 := range e { - all += fmt.Sprintf("move %s/%s/%s/*.* %s && ", mvPhotos, i, i2, mvPhotos) + winError(exec.Command("cd " + a + "/unzip/Photos/" + i + "/" + i2 + " && move *.* ../../").Start()) + fmt.Printf("%s \n", "cd "+a+"/unzip/Photos/"+i+"/"+i2+" && move *.* ../../") + winError(exec.Command("rd /s /q " + a + "/unzip/Photos/" + i + "/" + i2 + "/").Start()) + fmt.Printf("%s \n", "rd /s /q "+a+"/unzip/Photos/"+i+"/"+i2+"/") } } - all += "ls" - fmt.Printf("执行命令:%s\n", all) - cmd = exec.Command(all) - _ = cmd.Run() + winError(exec.Command("del " + a + "/unzip/zipfilelist.properties").Start()) + fmt.Printf("%s \n", "del "+a+"/unzip/zipfilelist.properties") // 生成压缩包 - zipFile := fmt.Sprintf("7z a 1.zip %s/unzip/", a) - fmt.Printf("执行命令:%s\n", zipFile) - cmd = exec.Command(zipFile) - _ = cmd.Run() + winError(exec.Command("7z a 1.zip " + a + "/unzip/").Start()) + fmt.Printf("%s \n", "7z a 1.zip "+a+"/unzip/") } var e = []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"} + +func winError(e error) { + if e != nil { + // fmt.Println(e) + } +}