Skip to content

Instantly share code, notes, and snippets.

@johnsonz
Created May 17, 2016 08:18
Show Gist options
  • Save johnsonz/8c76e3f13ed6cf5776d219ddc8644838 to your computer and use it in GitHub Desktop.
Save johnsonz/8c76e3f13ed6cf5776d219ddc8644838 to your computer and use it in GitHub Desktop.
go使用7z解压zip文件
func uncompress(dir string) {
err := filepath.Walk(dir, func(path string, file os.FileInfo, err error) error {
if file == nil {
return nil
}
if file.IsDir() {
return nil
}
ext := filepath.Ext(path)
if ext == ".zip" {
cmd := exec.Command("7z", "x", "-aoa", path, "-o"+dir)
err := cmd.Run()
if err != nil {
glog.Errorf("unzip err: %v\n", err)
}
}
return nil
})
if err != nil {
glog.Errorf("unzip err: %v\n", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment