How to zip a folder and unzip a file in python
%%shell
mkdir test
touch test/file1.txt
touch test/file2.txt
import shutil
dir_name = '/content/test/'
output_filename = 'test'
shutil.make_archive(output_filename, 'zip', dir_name)
import zipfile
path_to_zip_file ='/content/test.zip'
directory_to_extract_to = '/content/test1/'
with zipfile.ZipFile(path_to_zip_file, 'r') as zip_ref:
zip_ref.extractall(directory_to_extract_to)
use the code below to delete your zip file if needed:
import os
if os.path.exists(path_to_zip_file):
os.remove(path_to_zip_file)