Zip file is not created inside of the designated directory

I am using the code

from pathlib import Path
from zipfile import ZipFile

with ZipFile("files.zip", "w") as zip:
    for path in Path("ecommerce").rglob("*.*"):
        zip.write(path)

and the zip file is not created in the ecommerce directory. It is created with other files outside of the said directory. I have changed the path in the Path statement but to no avail. Any possible reason please.

I think I found the reason behind this the line
with ZipFile("files.zip", "w") as zip:

gotta be in full path as follows:

with ZipFile("e:/Tutorials/Mosh/mastery_course/ecommerce/files.zip", "w") as zip:

1 Like