glob()
noun
say it: “GLOB” /ˈɡlɑb/
A pathlib method that finds the files in a folder whose names fit a pattern, such as every name ending in .csv.
What does glob() do in pathlib?
glob() is the pathlib method that finds the files in a folder whose names match a pattern, where * stands for
any text. It gives them in no set order, so sorted() puts them in name order.
from pathlib import Path
files = sorted(Path("data/incoming").glob("week-*.csv"))
print(files[-1].name) # the last by name: week-2026-10-26.csv
In a sentence
- “He sorted what glob() gave back, so the newest file came last.”
- “glob() found all eight week files in the folder.”
Level: Journeyman · More Python terms at this level
Updated