Create Zip File from File List

  • Share this:

Code introduction


This function creates a zipfile and adds files from a provided list to it.


Technology Stack : zipfile, os

Code Type : Python Function

Code Difficulty : Intermediate


                
                    
def random_zipfile(filename, filelist):
    import zipfile
    import os
    with zipfile.ZipFile(filename, 'w') as zipf:
        for file in filelist:
            zipf.write(file, os.path.basename(file))
    return filename                
              
Tags: