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

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(".")

你可能感兴趣的:(一些没用的小玩意,python)