Forums

How to find files with a string

Hello I try to find a name of a file that contains 'TeNam' string But I cant

import os import sys def find_value(fname):
    value = 0
    with open(fname, encoding='cp866') as fn:
        try:
            for i in fn:
                if 'TeNam' in i:
                    print(fname)
        except IndexError:
            pass
    return {fname} def main():
    dirname = ('H:\\1\\3')
    os.chdir(dirname)
    res = {}
    for i in os.listdir(dirname):
        res.update(find_value(i))
    print('Filename is: ') if __name__ == "__main__":
    main()

Could you help?

What do you mean you can't? What is your code doing?