Combining Files into a Single Zip

  • Share this:

Code introduction


Combine two files into a single zip file.


Technology Stack : os, zipfile, shutil

Code Type : File processing

Code Difficulty : Intermediate


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

    zip_path = 'combined.zip'
    with zipfile.ZipFile(zip_path, 'w') as zipf:
        zipf.write(file1, os.path.basename(file1))
        zipf.write(file2, os.path.basename(file2))

    return zip_path                
              
Tags: