python深度遍歷
阿新 • • 發佈:2018-01-19
app deep filelist path sea arch tac 深度遍歷 ordinary import os
def DeepthSearch(path):
stack1 = []
OrdinaryFiles = []
stack1.append(path)
num = 0
while len(stack1) != 0:
one = stack1.pop()
filelist = os.listdir(one)
for item in filelist: abspath = os.path.join(one, item) if os.path.isdir(abspath): stack1.append(abspath) else: #print(abspath) OrdinaryFiles.append(abspath) num += 1 print("the %d time"%num, stack1) return OrdinaryFiles
pt = DeepthSearch(r"D:\dir")
for item in pt:
print(item)
python深度遍歷