def del_file(filepath):
"""
删除某一目录下的所有文件或文件夹
:param filepath: 路径
:return:
"""
del_list = os.listdir(filepath)
for f in del_list:
file_path = os.path.join(filepath, f)
if os.path.isfile(file_path):
os.remove(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
def fusion_multiple_mode_text_create_graph():
# basepath获取项目目录下文件保存地址
basepath = os.path.join(BASE_DIR, "../../data/Map_Data")
# 在postman中上传时需要填写key值
upload_files = request.files.getlist('text_data') # postman中 KEY
# 保存postman批量上传文档到本地、写盘操作
file_path = os.path.join(basepath, "fusion_multiple_modes_data","text_data")
del_file(file_path)
for file in upload_files:
filename = secure_filename(file.filename)
upload_path = os.path.join(file_path, filename)
file.save(upload_path)
参考文献:http://einverne.github.io/post/2017/07/flask-upload-files.html