Create and Move Zip File of Two Files

  • Share this:

Code introduction


Compresses two files into a single zip file and moves it to the current working directory.


Technology Stack : os, zipfile, shutil

Code Type : Function

Code Difficulty : Intermediate


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

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

    shutil.move('output.zip', os.path.join(os.getcwd(), 'output.zip'))                
              
Tags: