Created
April 17, 2020 19:47
-
-
Save stucka/5cda059627d3ed5fa950420922719e06 to your computer and use it in GitHub Desktop.
Save stuff to ZIPs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zipfile | |
import os | |
import glob | |
zipfilename = "/Users/mstucka/Dropbox/somedata.zip" | |
sourcedir = "somedata/" | |
filesalreadygot = [] | |
if os.path.exists(zipfilename): | |
with zipfile.ZipFile(zipfilename, 'r') as myzip: | |
filesalreadygot = myzip.namelist() | |
filesavailable = list(glob.glob(sourcedir + "*")) | |
with zipfile.ZipFile(zipfilename, "a") as myzip: # , compression="ZIP_DEFLATED", compresslevel=9 | |
for fileavailable in filesavailable: | |
basefilename = fileavailable.replace("\\", "/").replace(sourcedir, "") | |
if basefilename not in filesalreadygot: | |
print(f"Adding {basefilename}") | |
myzip.write(fileavailable, arcname=basefilename) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment