Zip Two Files into a Single Archive

  • Share this:

Code introduction


This function zips two files into a single zip file. It returns True if the output file exists, otherwise it returns False.


Technology Stack : os, zipfile

Code Type : File processing

Code Difficulty : Intermediate


                
                    
def zip_file(file1, file2, output):
    import os
    import zipfile

    with zipfile.ZipFile(output, 'w') as z:
        z.write(file1)
        z.write(file2)

    return os.path.exists(output)                
              
Tags: