a = []
b = []
num = 0
def func2(path1, treeShow):
global num
treeShow += " "
a = os.listdir(path1)

for  i in a:

    path2 = os.path.join(path1, i)

    if os.path.isfile(path2):
        print(treeShow, path2)
    else:
        b.append(path2)
        print("第%d次打印目录" % num, path2)
        num = num + 1

        func2(path2, "")

func2(r"D:\python自动化运维笔记", "")
print(b)