You can download this code by clicking the button below.
This code is now available for download.
Pack a file into a zip format and then rename the zip file to the original file name.
Technology Stack : os, zipfile, shutil
Code Type : File operation
Code Difficulty : Intermediate
def zipfiles(file1, file2):
import os
import zipfile
import shutil
with zipfile.ZipFile(file1, 'w') as zipf:
zipf.write(file2, os.path.basename(file2))
shutil.move(file1, file2)