Created
May 20, 2019 08:44
-
-
Save chenset/34987943a5a88c2fc6891ea05d084306 to your computer and use it in GitHub Desktop.
golang batch unzip
This file contains hidden or 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
| package main | |
| import ( | |
| "archive/zip" | |
| "io" | |
| "os" | |
| "path/filepath" | |
| ) | |
| func main() { | |
| // Warning: No error checking | |
| files, _ := filepath.Glob("*.zip") // Filename is case-sensitive | |
| for _, file := range files { | |
| unzip(file) | |
| } | |
| } | |
| func unzip(zipFIleName string) { | |
| z, _ := zip.OpenReader(zipFIleName) | |
| defer z.Close() | |
| for _, f := range z.File { | |
| os.MkdirAll(filepath.Dir(f.Name), 0644) | |
| rc, _ := f.Open() | |
| f, _ := os.Create(f.Name) | |
| io.Copy(f, rc) | |
| rc.Close() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment