import os
import collections
def guangdu(path):
commonFiles = []
que = collections.deque([])
print(que)
que.append(path)
print(que)
num = 0
while len(que) != 0:
one = que.popleft() filelist = os.listdir(one) for i in filelist: absPath = os.path.join(one, i) if os.path.isdir(absPath): que.append(absPath) num = num + 1 print("第%d次目录"%num, que) else: commonFiles.append(absPath) return commonFiles
arr = guangdu(r"D:\python自动化运维笔记")
for i in arr:
print(i)