Dev HelpersOpen library
← Back

Find files with glob

Find files with glob. A self-contained example using the Python standard library.

Open this example in the interactive library

Source code

from tempfile import TemporaryDirectory
from pathlib import Path
with TemporaryDirectory() as folder:
    root = Path(folder)
    for name in ['a.txt', 'b.csv', 'c.txt']:
        (root / name).touch()
    print(sorted(p.name for p in root.glob('*.txt')))

Sample output

['a.txt', 'c.txt']