> For the complete documentation index, see [llms.txt](https://treasuremaster.gitbook.io/python-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://treasuremaster.gitbook.io/python-docs/moduli-standartnoi-biblioteki-1/dostup-k-failam-i-papkam/fnmatch/fnmatch.fnmatch.md).

# fnmatch.fnmatch ()

### fnmatch.fnmatch ( *filename*, *pattern* )

Проверяет, соответствует ли строка имени файла ***filename*** строке шаблона ***pattern***, возвращая `True` или `False`. Оба параметра нормализованы по регистру с помощью [os.path.normcase ()](/python-docs/moduli-standartnoi-biblioteki-1/dostup-k-failam-i-papkam/os.path/os.path.normcase.md). [fnmatchcase ()](/python-docs/moduli-standartnoi-biblioteki-1/dostup-k-failam-i-papkam/fnmatch/fnmatch.fnmatchcase.md) можно использовать для сравнения с учетом регистра, независимо от того, является ли это стандартом для операционной системы.

В этом примере будут напечатаны все имена файлов в текущем каталоге с расширением `.txt`:

```python
import fnmatch
import os

for file in os.listdir('.'):
    if fnmatch.fnmatch(file, '*.txt'):
        print(file)
```
