python os.walk 遍历文件夹

匿名 (未验证) 提交于 2019-12-02 22:51:30
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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!