# 压缩月文件
startdir = "{}/searchText/{}".format(settings.BASE_DIR,strDay[0:10]) # 要压缩的文件夹路径
file_news = startdir + '.zip' # 压缩文件名称
z = zipfile.ZipFile(file_news, 'w', zipfile.ZIP_DEFLATED)
for dirpath, dirnames, filenames in os.walk(startdir):
fpath = dirpath.replace(startdir, '')
fpath = fpath and fpath + os.sep or ''
for filename in filenames:
z.write(os.path.join(dirpath, filename), fpath + filename)
z.close()
python 压缩指定文件夹
最新推荐文章于 2024-07-06 02:55:34 发布