I am trying to make the script for zipping the subfolders including inside files, and sub subfolders as well as it's own in python. below program is by entering the folder name but still, it won't work. Please, somebody, help with the script. Thank you so much in advance.
import zipfile
import os
import sys
def zipfolder(foldername, target_dir):
zipobj = zipfile.ZipFile(foldername + '.zip', 'w', zipfile.ZIP_DEFLATED)
rootlen = len(target_dir) + 1
for base, dirs, files in os.walk(target_dir):
for file in files:
fn = os.path.join(base, file)
zipobj.write(fn, fn[rootlen:])
zipfolder('20220711_RX_2_nomaly', '20220711_RX_3_nomaly') #insert your variables here
sys.exit()
structure of the subfolders and inside the files.
main folder(folder)
20220711_RX_2_nomaly(folder)
grey(folder)
xxxxx.jpg (files)
json (folder)
xxxx.json(files)
20220711_RX_3_nomaly(folder)
grey(folder)
xxxxx.jpg (files)
json (folder)
xxxx.json(files)
20220711_RX_4_nomaly(folder)
grey(folder)
xxxxx.jpg (files)
json (folder)
xxxx.json(files)
expected
20220711_RX_2_nomaly.zip
20220711_RX_3_nomaly.zip
20220711_RX_4_nomaly.zip