You can download this code by clicking the button below.
This code is now available for download.
This function takes a list of files and an output directory, and compresses all the files in the list into a single zip file.
Technology Stack : os, zipfile, pathlib
Code Type : File compression
Code Difficulty : Intermediate
def zipfiles(file_list, output_dir):
import os
import zipfile
from pathlib import Path
if not os.path.exists(output_dir):
os.makedirs(output_dir)
zip_filename = os.path.join(output_dir, 'archive.zip')
with zipfile.ZipFile(zip_filename, 'w') as zipf:
for file in file_list:
zipf.write(file, os.path.basename(file))
return zip_filename