1 import os 2 def tree_dir(dir, layer=0): 3 listdir = os.listdir(dir) 4 for index, file in enumerate(listdir): 5 file_path = os.path.join(dir, file) 6 print("| " * (layer - 1), end="") 7 if (layer > 0): 8 print("`--" if index == len(listdir) - 1 else "|--", end="") 9 print(file) 10 if (os.path.isdir(file_path)): 11 tree_dir(file_path, layer + 1) 12 13 tree_dir("..")