Zipping Files into a Single Zip File

  • Share this:

Code introduction


This function takes a list of files and an output zip file path, and zips all files into a single zip file.


Technology Stack : zipfile

Code Type : File compression

Code Difficulty : Intermediate


                
                    
def zipfiles(file_list, output_zip_path):
    with zipfile.ZipFile(output_zip_path, 'w') as zipf:
        for file in file_list:
            zipf.write(file, arcname=file)
    return "Files have been zipped successfully."                
              
Tags: