Add File to ZIP Archive

  • Share this:

Code introduction


Add a specified file to a ZIP file.


Technology Stack : zipfile, os

Code Type : File processing

Code Difficulty : Intermediate


                
                    
def zipfiles(file1, file2):
    import zipfile
    import os

    with zipfile.ZipFile(file1, 'w') as zipf:
        zipf.write(file2, os.path.basename(file2))

    return f'File {file2} has been added to {file1}'                
              
Tags: