0
点赞
收藏
分享

微信扫一扫

python os.walk 遍历文件夹


import os
for root, dirs, files in os.walk(".", topdown=False):
for name in files:
print(os.path.join(root, name))
for name in dirs:
print(os.path.join(root, name))

 

topdown --可选,为 True,则优先遍历 top 目录,否则优先遍历 top 的子目录(默认为开启)。如果 topdown 参数为 True,walk 会遍历top文件夹,与top 文件夹中每一个子目录。

返回的是一个三元组(root,dirs,files)。 dirs和files都是数组

 

​​http://www.waitingfy.com/archives/3842​​

 

举报

相关推荐

0 条评论