Zipping Files into a Single Zip Archive

  • Share this:

Code introduction


This function zips all files in the given file list into a single zip file and saves it to the specified output path.


Technology Stack : os, zipfile

Code Type : File compression

Code Difficulty : Intermediate


                
                    
def zipfiles(file_list, output_zip):
    import os
    import zipfile
    with zipfile.ZipFile(output_zip, 'w') as zipf:
        for file in file_list:
            zipf.write(file, os.path.basename(file))
    return True                
              
Tags: