I'm trying to write a zip file that contains a complete directory looking like this:
Aux
rices
rice with XYZ.txt
rice with ABC.txt
fruits
fruit with ASD.txt
meat
chicken
chicken with WER.txt
beef
beff with ASD.txt
...
I just want to compress the Aux folder with all the folders and txt files contained on it. However, I can only write the zipfile of the txt files, which are extracted from each directory.
The code I wrote is:
path = os.getcwd()
new_path = path + '/' + 'Aux'
new_title = 'new_book.zip'
with zf.ZipFile(new_title, 'w') as zipObj:
# Iterate over all the files in directory
for folderName, subfolders, filenames in os.walk(new_path):
for filename in filenames:
#create complete filepath of file in directory
filePath = os.path.join(folderName, filename)
# Add file to zip
zipObj.write(filePath, os.path.basename(filePath))
How would you do it?
Thanks