Python 一键压缩所有文件夹
import zipfile
import os
import sys
import time
now_file = os.getcwd()
for file in os.listdir(now_file):
if '.' not in file:
print('Please waitting %s to zip' % file)
try:
with zipfile.ZipFile("%s.zip"% file, mode='w') as write_log:
for dirpath, dirnames, filenames in os.walk(file):
#print (filenames)
for filename in filenames:
write_log.write(os.path.join(dirpath, filename))
except:
print ('%s to zip failed'% file)
time.sleep (3)
else:
continue