找出指定文件夹中的所有以txt结尾的文件,包括所有嵌套的子文件夹

# coding:utf-8
import os, re

for i in os.walk('d:'+os.sep):
    for txt in i[2]:
        try:
            txt = re.match(r'(.*)(.txt)', txt).group(0)
            print os.path.join(i[0], txt)
        except:
            pass
原文地址:https://www.cnblogs.com/jackyshan/p/3484298.html