Jupyter Notebook 默认是无法上传文件夹的,所以可以写一个脚本来解压上传的压缩包。(这里只支持 zip格式的压缩包)
import os
path = r"" # 这里写文件夹目录
filename = r"" # 这里写压缩包名字
extract_path = os.path.join(path, filename.rstrip(".zip"))
from pathlib import Path
import zipfile
if not os.path.exists(extract_path):
os.makedirs(extract_path)
with zipfile.ZipFile(os.path.join(path, filename), 'r') as f:
for fn in f.namelist():
extracted_path = Path(f.extract(fn, path))
print(fn)
extracted_path.rename(os.path.join(path.encode('cp437').decode('gbk'), fn))
zipfile 解压时默认使用 cp437 编码,在这里转码一下,防止出现乱码~