I am trying to write a python script to rename files (containing a predefined string with another predefined string). How do I rename files and folders in a zip file, without extracting the zip file (as it could be very large)?
import os
import zipfile
old_name="ABCD"
new_name="XYZ"
for d,s,files in os.walk(path):
for f in files:
if f.startswith(old_name) and f.endswith('.zip'):
with zipfile.ZipFile(f,'a') as zf:
for files_inside_zip in zf.namelist():
if files_inside_zip.startswith(old_name):
## Now I need to rename only this particular file
## some files are larger than 1 GB
## and contains 1000+ files
## so extracting all doest seems to be a good idea
zf.close