首先要装zipfile,没装过的就打开cmd安装一下
pip install zipfile
os是安装python自带的库,所以不需要安装
编写核心
压缩:
def zip_file():
zip_name = path.get() +'.zip'
z = zipfile.ZipFile(zip_name,'w',zipfile.ZIP_DEFLATED)
for dirpath, dirnames, filenames in os.walk(path.get()):
fpath = dirpath.replace(path.get(),'')
fpath = fpath and fpath + os.sep or ''
for filename in filenames:
z.write(os.path.join(dirpath, filename),fpath+filename)
z.close()
zip_file_message()
解压:
def unzip_file():
r = zipfile.is_zipfile(filename.get())
if r: