import os

FILE = "index.txt"

vertical = "│  "
branch = "├─ "
end = "└─ "

file_list = []

def walk_dir(path, level):
    file_list.append( (os.path.basename(path), level) )
    if os.path.isdir(path):
        for entry in os.listdir(path):
            walk_dir(entry, level + 1)

walk_dir(os.getcwd(), 0)

file_list2 = []

for i in range(len(file_list)):
    (name, depth) = file_list[i]
    file_list2.append( (name, depth, -1 if i == len(file_list) - 1 else file_list[i + 1][1]) )

next_depth = 0
final_str = ""
for (name, depth, next_depth) in file_list2:
    final_str += (vertical * max(0, depth - 1)) + (min(1, depth) * (end if depth > next_depth else branch)) + name + "\n"

with open(FILE, "w", encoding="utf-16") as f:
    f.write(final_str)