Browse Source

修改部分程序

master
VIVIMAN 2 years ago
parent
commit
dac0c7f540
  1. 17
      golang_learn/data_func/go_to_dir/readDir/linux读取指定目录下文件夹,文件向上移动两层.go
  2. 10
      golang_learn/data_func/go_to_dir/readDir/main.go
  3. 56
      golang_learn/data_func/go_to_dir/readDir/windows读取指定目录下文件夹,文件向上移动两层.go

17
golang_learn/data_func/go_to_dir/readDir/linux读取指定目录下文件夹,文件向上移动两层.go

@ -13,7 +13,7 @@ func main() {
del := "rm -rf ./unzip" del := "rm -rf ./unzip"
fmt.Printf("执行命令:%s\n", del) fmt.Printf("执行命令:%s\n", del)
cmd := exec.Command(del) cmd := exec.Command(del)
_ = cmd.Run() _ = cmd.Start()
// 执行解压操作,固定死目录和文件名称 // 执行解压操作,固定死目录和文件名称
// drc:drc jth:jth 同目录下存在 unzip 目录(用于解压文件) // 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) "%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) fmt.Printf("执行命令:%s\n", shellUnzip)
cmd = exec.Command(shellUnzip) cmd = exec.Command(shellUnzip)
_ = cmd.Run() _ = cmd.Start()
mvPhotos, all := fmt.Sprintf("cd %s/unzip/Photos", a), "" mvPhotos, all := fmt.Sprintf("cd %s/unzip/Photos", a), ""
fmt.Printf("执行命令:%s\n", mvPhotos) fmt.Printf("执行命令:%s\n", mvPhotos)
cmd = exec.Command(mvPhotos) cmd = exec.Command(mvPhotos)
_ = cmd.Run() _ = cmd.Start()
for _, i := range f { for _, i := range f {
for _, i2 := range f { for _, i2 := range f {
all += fmt.Sprintf("cd %s/%s/ && mv * ../ && ", i, i2) all += fmt.Sprintf("cd %s/%s/ && mv * ../ && ", i, i2)
@ -40,13 +40,20 @@ func main() {
all += "ls" all += "ls"
fmt.Printf("执行命令:%s\n", all) fmt.Printf("执行命令:%s\n", all)
cmd = exec.Command(all) cmd = exec.Command(all)
_ = cmd.Run() _ = cmd.Start()
// 生成压缩包 // 生成压缩包
zipFile := fmt.Sprintf("7z a 1.zip %s/unzip/", a) zipFile := fmt.Sprintf("7z a 1.zip %s/unzip/", a)
fmt.Printf("执行命令:%s\n", zipFile) fmt.Printf("执行命令:%s\n", zipFile)
cmd = exec.Command(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"} 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)
}
}

10
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)
}

56
golang_learn/data_func/go_to_dir/readDir/windows读取指定目录下文件夹,文件向上移动两层.go

@ -2,49 +2,55 @@ package main
import ( import (
"fmt" "fmt"
"os"
"os/exec" "os/exec"
"path"
"path/filepath" "path/filepath"
) )
func main() { func main() {
a, _ := filepath.Abs("./") a, _ := filepath.Abs("./")
fmt.Printf("当前目录:%s\n", a) fmt.Printf("当前目录:%s \n开始执行...\n", a)
a = "E:/" a = "E:/"
del := "del /S/Q unzip\\*.*" // 删除目录
fmt.Printf("执行命令:%s\n", del) winError(os.RemoveAll(path.Join([]string{a, "unzip"}...)))
cmd := exec.Command(del)
_ = cmd.Run() // 新建目录
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 目录(用于解压文件) // drc:drc jth:jth 同目录下存在 unzip 目录(用于解压文件)
shellUnzip := fmt.Sprintf("cd %s && "+ winError(exec.Command("cd " + a).Start())
"set Hy7zEncryptPath=%s/drc.drc && "+ winError(exec.Command("set Hy7zEncryptPath=" + a + "/drc.drc").Start())
"set Hy7zJarPath=%s/jth.jth && "+ winError(exec.Command("set Hy7zJarPath=" + a + "/jth.jth").Start())
"set Hy7zLogFileName=%s/hy_7z.log && "+ winError(exec.Command("set Hy7zLogFileName=" + a + "/hy_7z.log").Start())
"D:\\hzb2022\\tomcat8\\JDK1.8\\jre\\bin\\java -jar -Xms512m -XX:MetaspaceSize=256M -XX:MaxMetaspaceSize=512M "+ winError(exec.Command(a + "/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) a + "/jth.jth unzip " + a + "/1.hzb " + a + "/unzip " + a + "/unzip/Photos Z93z4H5b6z7d35b8").Start())
fmt.Printf("执行命令:%s\n", shellUnzip)
cmd = exec.Command(shellUnzip)
_ = cmd.Run()
mvPhotos, all := fmt.Sprintf("%s/unzip/Photos", a), ""
for _, i := range e { for _, i := range e {
for _, i2 := 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" winError(exec.Command("del " + a + "/unzip/zipfilelist.properties").Start())
fmt.Printf("执行命令:%s\n", all) fmt.Printf("%s \n", "del "+a+"/unzip/zipfilelist.properties")
cmd = exec.Command(all)
_ = cmd.Run()
// 生成压缩包 // 生成压缩包
zipFile := fmt.Sprintf("7z a 1.zip %s/unzip/", a) winError(exec.Command("7z a 1.zip " + a + "/unzip/").Start())
fmt.Printf("执行命令:%s\n", zipFile) fmt.Printf("%s \n", "7z a 1.zip "+a+"/unzip/")
cmd = exec.Command(zipFile)
_ = cmd.Run()
} }
var e = []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"} 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)
}
}

Loading…
Cancel
Save