Skip to content

Instantly share code, notes, and snippets.

@chenset
Created May 20, 2019 08:44
Show Gist options
  • Select an option

  • Save chenset/34987943a5a88c2fc6891ea05d084306 to your computer and use it in GitHub Desktop.

Select an option

Save chenset/34987943a5a88c2fc6891ea05d084306 to your computer and use it in GitHub Desktop.
golang batch unzip
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