import subprocess path = ROOT_DIR result = (subprocess.check_output(['tree', '--dirsfirst', path]) .decode("utf-8", "strict")) file_list = result.split('\n') root = file_list[0] file_list = file_list[1:-3] header_fmt = "
{}