What is wrong in this code? I want to find a specified file in folder. Thansk for your help.
import os, fnmatch
def find(root, mask): //Error
files_list = os.listdir(os.path.abspath(root))
for filename in fnmatch.filter(files_list, mask):
yield filename
def test():
res = find ('D:\\Sample\\', 'hallo.txt')
test()
the error:
Error: Traceback (most recent call last): def find(root, mask): NoneType
Your function is a generator, it will yield filenames one by one. You can call
listonresif you want a list of all matches:Also your default argument of
root=os.dirmakes no sense. Maybe use'.'?