Python Forum
how can i adding custom path for saving the zip_file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how can i adding custom path for saving the zip_file
#1
Bug 
I am creating a zip file using the zipfile module.It works like a charm. but thatsĀ file, saved in the executed script place.
my script path is a:
c:/User/Administrator/script.py
and the zipfile saved in:
c:/User/Administrator/backup.zip

but i want, creating a zipfile, in another path, like this:
d:/backups/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.
snippsat write Oct-09-2021, 08:58 AM:
Added code tag in your post,look at BBCode on how to use.
Reply
#2
You give path to where read from(if not in same folder as script) and destination.
Example.
import zipfile
import pathlib

file_path = r'G:\div_code\answer\weather'
dst = r'G:\div_code\answer\backup.zip'
with zipfile.ZipFile(dst, 'w') as zip_file:
    for file in pathlib.Path(file_path).iterdir():
        if file.is_file():
            print(f'zipped --> {file.name}')
            zip_file.write(file)
Output:
zipped --> file_1_0_.txt zipped --> file_33.txt zipped --> key.ini zipped --> open_weather.py zipped --> to_zip.txt
demonvictor likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  File path by adding various variables Mishal0488 2 1,026 Apr-28-2023, 07:17 PM
Last Post: deanhystad
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,203 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Downloading And Saving Zip Files To A Particular Path Folder eddywinch82 2 2,557 Jan-06-2020, 07:56 PM
Last Post: eddywinch82
  Adding markers to Folium map only adding last element. tantony 0 2,121 Oct-16-2019, 03:28 PM
Last Post: tantony
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,741 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908
  Adding into Path var while silent installation of Python Erik 7 7,221 Nov-20-2017, 04:16 PM
Last Post: Erik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020