package main
import (
"archive/zip"
"io"
"os"
)
func main() {
// Specify the path to the zip file you want to unzip
zipFilePath := "/path/to/your/file.zip"
// Specify the directory where you want to extract the contents
extractDir := "/path/to/extract/directory"
// Open the zip file for reading
zipFile, err := zip.OpenReader(zipFilePath)
if err != nil {
panic(err)
}
defer zipFile.Close()
// Create the extraction directory if it doesn't exist
os.MkdirAll(extractDir, os.ModePerm)
// Iterate through each file in the zip archive
for _, file := range zipFile.File {
// Open the file from the zip archive
zippedFile, err := file.Open()
if err != nil {
panic(err)
}
defer zippedFile.Close()
// Create the destination file in the extraction directory
destFilePath := extractDir + "/" + file.Name
destFile, err := os.Create(destFilePath)
if err != nil {
panic(err)
}
defer destFile.Close()
// Copy the contents of the zipped file to the destination file
_, err = io.Copy(destFile, zippedFile)
if err != nil {
panic(err)
}
}
}