Skip to content

Instantly share code, notes, and snippets.

@benhg
Created May 19, 2018 00:12
Show Gist options
  • Save benhg/5b0f66a2ddf336a87da410ede686532f to your computer and use it in GitHub Desktop.
Save benhg/5b0f66a2ddf336a87da410ede686532f to your computer and use it in GitHub Desktop.
Run in a cell in a jupyter notebook to get all files in a tgz archive to download
import os
import tarfile
tarFileName='currdir.tar'
def RecursiveFiles(dn='.',ignoreTarFile=tarFileName):
ignore={'.pynb_checkpoints','pycache',ignoreTarFile}
for dirname,subdirs,files in os.walk(dn):
if os.path.basename(dirname) in ignore: continue
for fn in files:
fname=os.path.join(dirname,fn)
yield(fname)
return # there is a return, it should be deleted if it doesn't work
def makeTarFile(dn='.',tfn=tarFileName):
tar=tarfile.open(tfn,'w')
for name in RecursiveFiles(dn,tfn):
tar.add(name)
tar.close()
makeTarFile()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment