Compress Files into a ZIP Archive

  • Share this:

Code introduction


This function compresses a list of files into a single ZIP file and returns the path of the generated ZIP file.


Technology Stack : zipfile

Code Type : File compression

Code Difficulty : Intermediate


                
                    
def zipfiles(file_list, output_file):
    with open(output_file, 'wb') as f_out:
        with zipfile.ZipFile(f_out, 'w') as zipf:
            for file in file_list:
                zipf.write(file)
    return output_file                
              
Tags: