Skip to content

Instantly share code, notes, and snippets.

@johnsonz
Created May 17, 2016 08:22
Show Gist options
  • Save johnsonz/a9fc253dc97d19d0d72dc0b5fabfb0cc to your computer and use it in GitHub Desktop.
Save johnsonz/a9fc253dc97d19d0d72dc0b5fabfb0cc to your computer and use it in GitHub Desktop.
go使用winrar解压rar文件
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 == ".rar" {
cmd := exec.Command("unrar", "x", "-ad", "-o+", path, dir)
err := cmd.Run()
if err != nil {
glog.Errorf("unrar 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