title: Folder and files upload with Flask
body: <p>I can upload a File with flask by following <a href="http://flask.pocoo.org/docs/patterns/fileuploads/" rel="noreferrer">Uploading Files</a>:</p>
  
  <ol>
  <li>A <code>&lt;form&gt;</code> tag is marked with <code>enctype=multipart/form-data</code> and an <code>&lt;input type=file&gt;</code> is placed in that form.</li>
  <li>The application accesses the file from the files dictionary on the request object.</li>
  <li>Use the <code>save()</code> method of the file to save the file permanently somewhere on the filesystem.</li>
  </ol>
  
  <p>But I don't know how to upload folder or some files. I searched, and I found <a href="https://stackoverflow.com/questions/11817182/uploading-multiple-files-with-flask?rq=1">Uploading multiple files with Flask</a>.</p>
  
  <p>However, still I don't know how to upload a folder and files that belong to the folder.</p>
  
  <p>Could you please tell how? </p>
  
  <hr>
  
  <p>Directory tree I am working on:</p>
  
  <pre><code>.
  ├── manage.py
  ├── templates
  │   ├── file_upload.html
  │   └── hello.html
  └── uploads
      ├── BX6dKK7CUAAakzh.jpg
      └── sample.txt
  </code></pre>
  
  <p>Source code of uploading file:</p>
  
  <pre><code>from flask import Flask,abort,render_template,request,redirect,url_for
  from werkzeug import secure_filename
  import os
  app = Flask(__name__)
  UPLOAD_FOLDER = './uploads'
  app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER 
  @app.route('/')
  def index():
      return redirect(url_for('hello'))
  
  @app.route('/hello/')
  @app.route('/hello/&lt;name&gt;')
  def hello(name = None):
      return render_template('hello.html',name=name)
  
  @app.route('/upload/',methods = ['GET','POST'])
  def upload_file():
      if request.method =='POST':
          file = request.files['file']
          if file:
              filename = secure_filename(file.filename)
              file.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
              return hello()
      return render_template('file_upload.html')
  
  
  if __name__ == '__main__':
      app.run(debug = True)
  </code></pre>
  
  <p>template for file uploading(manage.py):</p>
  
  <pre><code>&lt;!doctype html&gt;
  &lt;title&gt;Upload new File&lt;/title&gt;
  &lt;h1&gt;Upload new File&lt;/h1&gt;
  &lt;form action='' method="POST" enctype="multipart/form-data"&gt;
      &lt;p&gt;&lt;input type='file' name='file[]' multiple=''&gt;
      &lt;input type='submit' value='upload'&gt;
      &lt;/p&gt;
  
  &lt;/form&gt;
  </code></pre>