You can download this code by clicking the button below.
This code is now available for download.
This function compresses all files in the specified folder into a single ZIP file.
Technology Stack : os, zipfile
Code Type : File compression
Code Difficulty : Intermediate
def zip_file(input_folder, output_zip):
import os
import zipfile
with zipfile.ZipFile(output_zip, 'w') as zipf:
for foldername, subfolders, filenames in os.walk(input_folder):
for filename in filenames:
file_path = os.path.join(foldername, filename)
zipf.write(file_path, os.path.relpath(file_path, input_folder))
return output_zip