forked from go/golangs_learn
VIVIMAN
3 years ago
1 changed files with 61 additions and 0 deletions
@ -0,0 +1,61 @@ |
|||
package main |
|||
|
|||
import ( |
|||
"github.com/yeka/zip" |
|||
"io/ioutil" |
|||
"log" |
|||
"os" |
|||
) |
|||
|
|||
var pwd = `Qw^e1@10&++Hzb...?8` |
|||
|
|||
func main() { |
|||
dirPath := `D:\hzb2021` |
|||
fileName := `2022122235133` |
|||
data := `data` |
|||
qggwy := `qggwy` |
|||
demo := `111` |
|||
fileType := `.gz` |
|||
os.Mkdir(dirPath+`\`+demo, os.ModePerm) |
|||
os.Mkdir(dirPath+`\`+fileName, os.ModePerm) |
|||
UnZip(dirPath+`\`+fileName+fileType, dirPath, pwd) |
|||
UnZip(dirPath+`\`+fileName+`\`+data+fileType, dirPath+`\`+demo, pwd) |
|||
UnZip(dirPath+`\`+fileName+`\`+qggwy+fileType, dirPath+`\`+demo, pwd) |
|||
|
|||
// 移除文件
|
|||
// os.Remove(dirPath + `\` + fileName + fileType)
|
|||
os.Remove(dirPath + `\` + fileName + `\` + data + fileType) |
|||
os.Remove(dirPath + `\` + fileName + `\` + qggwy + fileType) |
|||
} |
|||
|
|||
func UnZip(dst, src, pwd string) { |
|||
r, err := zip.OpenReader(dst) |
|||
if err != nil { |
|||
log.Fatal(err) |
|||
} |
|||
defer r.Close() |
|||
|
|||
for _, f := range r.File { |
|||
if f.IsEncrypted() { |
|||
f.SetPassword(pwd) |
|||
} |
|||
r, err := f.Open() |
|||
if err != nil { |
|||
log.Fatal(err) |
|||
} |
|||
|
|||
buf, err := ioutil.ReadAll(r) |
|||
if err != nil { |
|||
log.Fatal(err) |
|||
} |
|||
defer r.Close() |
|||
|
|||
if f.FileInfo().IsDir() { |
|||
// Make Folder
|
|||
os.MkdirAll(src+"/"+f.Name, os.ModePerm) |
|||
} else { |
|||
log.Print(`输出文件:`, f.FileHeader.Name) |
|||
ioutil.WriteFile(src+"/"+f.Name, buf, os.ModePerm) |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue