Created
May 17, 2016 08:22
-
-
Save johnsonz/a9fc253dc97d19d0d72dc0b5fabfb0cc to your computer and use it in GitHub Desktop.
go使用winrar解压rar文件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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