os.walk的用法

import os
path = 'C:\\aa'
for root,dirs,files in os.walk(path):
    print("Root=",root,'dirs=',dirs,'files =',files)

执行结果:

Root= C:\aa dirs= ['bb'] files = ['b1.txt', 'b2.txt']
Root= C:\aa\bb dirs= ['cc'] files = ['cc1.txt', 'cc2.txt']
Root= C:\aa\bb\cc dirs= ['dd'] files = ['d1.txt', 'd2.txt', '新建 RTF 文档.rtf']
Root= C:\aa\bb\cc\dd dirs= [] files = []

 




posted @ 2018-11-22 20:57  开始认识  阅读(569)  评论(0编辑  收藏  举报