![](/img/trans.png)
[英]Extract zip file and nested zip files into target directory using Python
[英]extract zip files using python
import zipfile
fantasy_zip = zipfile.ZipFile('E:\\Shared\\DOWNLOADED\\c.zip')
fantasy_zip.extractall('E:\\Shared\\DOWNLOADED\\extract)
fantasy_zip.close()
我的密码是“你好”我怎么能包含提取密码?
Python zipfile
包可以解压缩具有密码的文件。
def unzip_folder(zip_folder, destination, pwd):
"""
Args:
zip_folder (string): zip folder to be unzipped
destination (string): path of destination folder
pwd(string): zip folder password
"""
with zipfile.ZipFile(zip_folder) as zf:
zf.extractall(
destination, pwd=pwd.encode())
在你的情况下,
import zipfile
zip_folder = 'E:\\Shared\\DOWNLOADED\\c.zip'
destination = 'E:\\Shared\\DOWNLOADED'
pwd = '<YOUR_PASSWORD>'
with zipfile.ZipFile(zip_folder) as zf:
zf.extractall(
destination, pwd=pwd.encode())
from zipfile import ZipFile
with ZipFile('E:\Shared\DOWNLOADED\c.zip') as fileobj:
fileobj.extractall(pwd='hello')
请注意,python3的zipfile仅支持使用基于CRC-32加密的加密zip文件这似乎是linux上“zip”程序的默认设置,但这不适用于AES加密或许多基于Windows的zip解决方案。 https://github.com/python/cpython/blob/3.6/Lib/zipfile.py了解更多详情
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.