import os fnmatch def locate pattern root os curdir for path dirs file

1
2
3
4
5
6
7
8
import os, fnmatch
def locate(pattern, root=os.curdir):
for path, dirs, files in os.walk(os.path.abspath(root)):
for filename in fnmatch.filter(files, pattern):
yield os.path.join(path, filename)
# пример использования
for fname in locate("*"):
print(fname)