码迷,mamicode.com
首页 > 编程语言 > 详细

python深度遍历

时间:2018-01-19 00:14:57      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:list   lis   ordinary   path   std   pytho   else   深度   item   

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深度遍历

标签:list   lis   ordinary   path   std   pytho   else   深度   item   

原文地址:http://blog.51cto.com/victor2016/2062646

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!