Home > Software engineering >  how can i adding custom path for saving the zip_file
how can i adding custom path for saving the zip_file

Time:10-10

I am creating a zip file using the zipfile module. It works like a charm. but that's file, saved in the executed script place. my script path is a: [b]c:/User/Administrator/[/b]script.py and the zipfile saved in: [b]c:/User/Administrator/[/b]backup.zip

but I want, [b]creating a zipfile, in another path[/b], like this: [b]d:/backups/[/b]backup.zip

my code like this:

import zipfile

zip_file = zipfile.ZipFile("backup.zip", 'w')
with zip_file:
    for file in filePaths:
        zip_file.write(file)

my question is a how can I adding custom path for saving the zip_file. because I have not an enough space in C:

tnx a lot.

CodePudding user response:

Give the path you want to ZipFile function.
When you give only the name of the file, it will save the file in the current directory which the program is running.
Do this instead:

import zipfile
# For example you want to save it in drive 'D'
path = "D:\\PathToYourDir\\backup.zip"
zip_file = zipfile.ZipFile(path, 'w')
with zip_file:
    for file in filePaths:
        zip_file.write(file)
  • Related