Merging Files into a ZIP Archive

  • Share this:

Code introduction


This function merges files from two lists into a single ZIP file. Files from the first list are used as the source files, and their corresponding names from the second list will be used as the names in the compressed file.


Technology Stack : zipfile

Code Type : File processing

Code Difficulty : Intermediate


                
                    
def zipfiles(file_list1, file_list2):
    zip_file = zipfile.ZipFile('combined.zip', 'w')
    for file1, file2 in zip(file_list1, file_list2):
        zip_file.write(file1, arcname=file2)
    zip_file.close()                
              
Tags: