首页 > 编程语言 > 详细

Python shutil模块

时间:2019-09-29 20:18:13      阅读:105      评论:0      收藏:0      [点我收藏+]

参考链接: https://www.cnblogs.com/zhangboblogs/p/7821702.html

      https://www.cnblogs.com/xiangsikai/p/7787101.html

找了一圈的博客发现大大小小都有问题,还是看源码吧

@app.route(/index/, methods=[GET, POST])
def index():
    import os
    import shutil
    if request.method == GET:
        return render_template(index.html)
    # POST
    file_obj = request.files.get(code)
    # print(file_obj)     # <FileStorage: ‘bbs.zip‘ (‘application/zip‘)>
    # print(file_obj.filename)    # bbs.zip
    print(type(file_obj))   # <class ‘werkzeug.datastructures.FileStorage‘>
    # from werkzeug.datastructures import FileStorage   # 查看源码
    file_path = os.path.join(os.getcwd(), files, file_obj.filename)
    # print(file_path)
    file_obj.save(file_path)
    # 解压
    extract_dir = os.path.join(os.getcwd(), files)
    shutil.unpack_archive(file_path, extract_dir=extract_dir)
    # save(self, dst, buffer_size=16384)  dst是目标文件,包括文件名

    return 上传成功

 

Python shutil模块

原文:https://www.cnblogs.com/wt7018/p/11609202.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!