Many files in a folder. I want to zip them all. Every 10 files will be added to a zip file.
import os, glob import numpy as np import zipfile file_folder = "C:\\ABC\\DEF\\" all_files = glob.glob(file_folder + "/*.*") several_lists= np.array_split(all_files, 10) for num, file_names in enumerate(several_lists): ZipFile = zipfile.ZipFile(file_folder + str(num) + ".zip", "w" ) for f in file_names: ZipFile.write(f, compress_type=zipfile.ZIP_DEFLATED) ZipFile.close()
The generated zip files contains also the paths, i.e. every zip file has a folder DEF in a folder ABC. The file themselves are in DEF.
I changed the line to:
Error pops for:
WindowsError: [Error 2] The system cannot find the file specified:
How to correct it? Thank you.
Btw, is there a big difference in zip and rar file created by Python?