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']
