import zipfile,os
os.chdir('c:\\delicious')
exampleZip = zipfile.ZipFile('example.zip')
exampleZip.namelist()
spamInfo = exampleZip.getinfo('spam.txt')
spamFileSize = spamInfo.file_size
spamCompressSize = spamInfo.compress_size
print('Compressed file is %sx smaller!' % (round(spamFileSize / spamCompressSize,2)))
exampleZip.extractall()
exampleZip.close()
#create a *.zip
newZip = zipfile.ZipFile('new.zip','w')
newZip.write ('spam.txt', compress_type=zipfile.ZIP_DEFLATED)
newZip.close()
examNewZip = zipfile.ZipFile('new.zip')
print('new.zip include file is: %s' % (examNewZip.namelist()))
spamFileSize = spamInfo.file_size 获取文件大小
spamCompressSize = spamInfo.compress_size 获取压缩后文件大小
examplZip.extractall() 将解压压缩包,如果解压目录下存在相同目录,将覆盖。
newZip.write() 目前是支持将一个文件添加到zip文件中(本人理解)
压缩比例,解压缩,添加一个文件到zip文件中
本文暂时没有评论,来添加一个吧(●'◡'●)