from flask import Flask, send_from_directory import os app = Flask(__name__) root_dir = r'c:/dld' def root_dir_file_list(folder): file_list_str = '' for filename in os.listdir(folder): if os.path.isdir(folder+'\\'+filename): li = f'''
  • {filename}
  • ''' else: li = f'''
  • {filename}
  • ''' file_list_str = file_list_str + li return file_list_str def sub_dir1_file_list(folder): if folder[-1] == '\\': folder = folder[:-1] print(folder) sub_dir1 = folder.split('\\')[-1] file_list_str = '' for filename in os.listdir(folder): li = f'''
  • {filename}
  • ''' file_list_str = file_list_str + li return file_list_str def sub_dir2_file_list(folder): pass def create_html(file_list_str): html = f''' Download

    Directory listing


    ''' return html @app.route('/') def index(): return create_html(root_dir_file_list(root_dir)) @app.route('/') def sub_dir1_page(sub_dir): dir_name = root_dir + '\\' + sub_dir return create_html(sub_dir1_file_list(dir_name)) @app.route('//') def sub_dir2_page(sub_dir1, sub_dir2): pass @app.route('/') def download_root(filename): return send_from_directory(root_dir, filename) @app.route('//') def download_subdir1(sub_dir, filename): dir_name = root_dir + '\\' + sub_dir return send_from_directory(dir_name, filename) @app.route('///') def download_subdir2(sub_dir1, sub_dir2, filename): pass httpport=31404 app.run(host='0.0.0.0',port=httpport,debug=False)