【Python】遍历文件夹

本地E盘上有一个why文件夹,why文件夹下有3个文件夹,分别是one,two,three,这三个文件夹下面分别有自己的txt文件:

import os
import os.path
rootdir="E:\why"

for zhu,ci,files in os.walk(rootdir):
for f in files:
print os.path.join(zhu,f)

 

输出为:

E:\why\one\1.1.txt
E:\why\one\1.2.txt
E:\why\three\wa.txt
E:\why\two\2.1.txt
E:\why\two\2.2.txt

posted @ 2018-03-22 16:08  foreverlove~  阅读(195)  评论(0编辑  收藏  举报