标签:跳转 for 目录 down target tar blog blank not
详细介绍点击跳转 Jupyter主页
Jupyter Notebook默认只能选择一个文件下载
如需要保留层级目录并批量打包下载
在需要下载目录新建一个ipynb
运行如下代码
import os
import tarfile
def recursive_files(dir_name=‘.‘, ignore=None):
for dir_name, subdirs, files in os.walk(dir_name):
if ignore and os.path.basename(dir_name) in ignore:
continue
for file_name in files:
if ignore and file_name in ignore:
continue
yield os.path.join(dir_name, file_name)
def make_tar_file(dir_name=‘.‘, tar_file_name=‘tarfile.tar‘, ignore=None):
tar = tarfile.open(tar_file_name, ‘w‘)
for file_name in recursive_files(dir_name, ignore):
tar.add(file_name)
tar.close()
dir_name = ‘.‘
tar_file_name = ‘archive.tar‘
ignore = {‘.ipynb_checkpoints‘, ‘__pycache__‘, tar_file_name}
make_tar_file(dir_name, tar_file_name, ignore)
运行后在当前目录下生成一个归档文件
选中archive.tar后Download
https://zhuanlan.zhihu.com/p/351058634
本文作者:双份浓缩馥芮白
原文链接:https://www.cnblogs.com/Flat-White/p/14920718.html
版权所有,如需转载请注明出处。
【Python】Jupyter Notebook保留层级结构 批量下载
标签:跳转 for 目录 down target tar blog blank not
原文地址:https://www.cnblogs.com/Flat-White/p/14920718.html