# os.walk() 方法用于通过在目录树中游走输出在目录中的文件名,向上或者向下。
# 第一个参数top 是你所要遍历的目录的地址, 返回的是一个三元组(root,dirs,files)。
# 第二个参数topdown --可选,为 True,则优先遍历 top 目录,否则优先遍历 top 的子目录(默认为开启)。如果 topdown 参数为 True,walk 会遍历top文件夹,与top 文件夹中每一个子目录。
import os
all = os.walk(".", topdown=False)
for root, dirs, files in all:
for name in files:
print(os.path.join(root, name))
for name in dirs:
print(os.path.join(root, name))