Python遍历文件夹, 找出最深文件夹
dir_path = r"xxx"
ret = os.walk(dir_path)
dir_dict = {}
def dir_walk(dir):
for ele_dir in dir:
if ele_dir[1]:
for i in ele_dir[1]:
dir_name = os.path.join(ele_dir[0], i)
dir_walk(os.walk(dir_name))
else:
tmp_list = ele_dir[0].split("\\")
dir_dict[len(tmp_list)] = ele_dir[0]
dir_walk(ret)
for k in sorted(dir_dict)[::-1]:
print(k, "\t", dir_dict[k])
del dir_dict