Created
May 19, 2018 00:12
-
-
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
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 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