python

  感觉这个没什么好说的:

import os


def rev(path: str, i=0):
    s = '+' * i + path.split('/')[-1] + '
'
    for _ in os.listdir(path):
        if os.path.isdir(path + '/' + _):
            s += rev(path + '/' + _, i + 1) + '
'
        elif os.path.isfile(path + '/' + _):
            s += '+' + '+' * i + _ + '
'
    return s


print(rev('D:/PycharmProjects'))

  

原文地址:https://www.cnblogs.com/darkchii/p/12757890.html