查找某些目录下指定格式文件中包含特定词汇的文件集合

import os


def checkfilelist(nowDir):
    for home, dirs, files in os.walk(nowDir):
        for filename in files:
            nowfile = os.path.join(home, filename)
            if ".go" in nowfile:
                f = open(nowfile, "r", encoding='utf-8')
                for nowline in f.readlines():
                    if "add new" in nowline:
                        print(nowfile)
                        break
                f.close()


checkfilelist(".")

猜你喜欢

转载自blog.csdn.net/eliforsharon/article/details/127109146