Skip to content

Instantly share code, notes, and snippets.

@tadone
Created October 30, 2017 13:37
Show Gist options
  • Save tadone/be55f2b3b42013fd7bfc381a408d0744 to your computer and use it in GitHub Desktop.
Save tadone/be55f2b3b42013fd7bfc381a408d0744 to your computer and use it in GitHub Desktop.
[Zip dir function w/ exclude dirs] Zip up directory excluding some dirs #python
exclude = ['dir1','dir2']
def zipdir(path, ziph, exclude):
'''Zip up the directory excluding some subdirs'''
# ziph is zipfile handle
for dirname, subdirs, files in os.walk(path):
subdirs[:] = [d for d in subdirs if d not in exclude]
for file in files:
ziph.write(os.path.join(dirname, file))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment