python 简单遍历文件...

来源:互联网 发布:软件测试和网络工程师 编辑:程序博客网 时间:2024/06/04 18:49
import os

这里利用了迭代器.


def walk(path):
if os.path.isdir(path):
for file in os.listdir(path):
file_path = os.path.join(path, file)
for sub_file in walk(file_path):
yield sub_file
else:
yield path


for file in walk("/home/long"):
print file
原创粉丝点击