Compress Two Files into a Single ZIP

  • Share this:

Code introduction


This function compresses two files into a single ZIP file. The first argument is the name of the source file, the second argument is the name of another source file, and the third argument is the name of the output ZIP file.


Technology Stack : shutil, zipfile

Code Type : File compression

Code Difficulty : Intermediate


                
                    
def zip_file(filename1, filename2, output_filename):
    import shutil
    import zipfile
    with zipfile.ZipFile(output_filename, 'w') as zipf:
        zipf.write(filename1, arcname=filename1)
        zipf.write(filename2, arcname=filename2)                
              
Tags: