Python fnmatch - zhongjiajie/zhongjiajie.github.com GitHub Wiki

Python-fnmatch

Unix filename pattern matching, 官网

fnmatch.fnmatch(filename, pattern)

import fnmatch
import os

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

fnmatch.filter(names, pattern)

Return the subset of the list of names that match pattern. It is the same as [n for n in names if fnmatch(n, pattern)], but implemented more efficiently.


⚠️ **GitHub.com Fallback** ⚠️