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 = []

 




相关文章:

  • 2022-01-10
  • 2021-06-28
  • 2021-11-01
  • 2021-09-22
猜你喜欢
  • 2021-10-01
  • 2021-10-18
  • 2022-12-23
  • 2021-10-11
  • 2021-07-08
  • 2021-08-20
相关资源
相似解决方案