使用 python 提取 zip 文件
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()
我的密码是"hello"
如何包含要提取的密码?
from zipfile import ZipFile
with ZipFile('E:\Shared\DOWNLOADED\c.zip') as fileobj:
fileobj.extractall(pwd='hello')
Take care, python3's zipfile only supports encrypted zip files that
use CRC-32 based encryption This seems to be the default for the "zip"
program on linux, but this doesn't work for AES encryption, or for
many Windows based zip solutions See
https://github.com/python/cpython/blob/3.6/Lib/zipfile.py for more
details
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())
import zipfile
fantasy_zip = zipfile.ZipFile('E:\Shared\DOWNLOADED\c.zip')
fantasy_zip.extractall('E:\Shared\DOWNLOADED\extract)
fantasy_zip.close()
我的密码是"hello" 如何包含要提取的密码?
from zipfile import ZipFile
with ZipFile('E:\Shared\DOWNLOADED\c.zip') as fileobj:
fileobj.extractall(pwd='hello')
Take care, python3's zipfile only supports encrypted zip files that use CRC-32 based encryption This seems to be the default for the "zip" program on linux, but this doesn't work for AES encryption, or for many Windows based zip solutions See https://github.com/python/cpython/blob/3.6/Lib/zipfile.py for more details
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())