代码
def dir(path, n=1):
if not os.path.isdir(path):
print('错误:{}'.format("路径非文件夹 "), path)
return
try:
global count
for file in os.listdir(path):
f = os.path.join(path, file)
print("——" * n, file)
count += 1
if os.path.isdir(f):
n2 = n + 1
dir(f, n=n2)
print()
except:
pass
if __name__ == '__main__':
count = 1
dir(r"F:\PCode")
print("权限文件总数:{}".format(count))