๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ glob.html
glob โ€” Unix style pathname pattern expansion โ€” Python 3.15.2 documentation
The glob module finds pathnames using pattern matching rules similar to the Unix shell. No tilde expansion is done, but *, ?, and character ranges expressed with [] will be correctly matched.
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ glob-in-python
Glob in Python Explained | Built In
Glob is a Python module thatโ€™s used to search for file path names that match a specific pattern.
Discussions

glob.glob vs Path.glob
glob.glob returns meager ol' strings whereas Path.glob returns you easy to work with path objects. More on reddit.com
๐ŸŒ r/learnpython
7
3
January 8, 2023
Python glob multiple filetypes - Stack Overflow
I like this approach - if glob's expressiveness isn't powerful enough, upgrade to a more powerful regex system, don't hack on it using e.g. itertools because subsequent pattern changes also have to be hacky (say you want to allow upper and lower case). Oh, and it might be cleaner to write '.*\.(txt|sql)' 2013-08-29T12:39:34.557Z+00:00 ... While Python... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Which is much more efficient, glob.glob() or os.listdir()?

There's going to be almost no difference. Under the covers, glob is essentially doing the same thing as your listdir code (ie calling listdir and then checking if the paths match a particular pattern). In fact, it's actually doing a bit more work since it's more general (ie. handles more types of patterns than just "end of file"), so it's actually going to be the slower one.

However the difference is going to be pretty much undetectable unless you're looking at directories with millions of files (and even then is going to be pretty negligible). Computers are fast, and this kind of check is going to take a tiny amount of time - the time to actually access the disk is always going to completely dwarf it - trying to optimise it is like trying to reduce the time it takes a train door to open in an effort to cut down the time a 10 minute journey takes. Sure: maybe you could cut half a second off the time with a faster door, but it's not going to be noticable next to the travel time.

however I need to specify a chdir() before it starts

Not at all - you can include the path as part of your pattern. Ie glob.glob("path/to/file/*.pdf")

More on reddit.com
๐ŸŒ r/learnpython
10
5
November 22, 2016
python - How to use glob() to find files recursively? - Stack Overflow
This works better than pathlib.Path('./path/').glob('*/') because it also so in folder with size of 0 2020-04-18T15:14:07.927Z+00:00 ... In Python 3.9.1, recursive is set to False by default. More on stackoverflow.com
๐ŸŒ stackoverflow.com
computer operation of listing files that match a wildcard pattern
glob (programming) - Wikipedia
glob() (/ษกlษ’b/) is a POSIX C function for globbing, which is the archetypal use of pattern matching against the names in a filesystem directory such that a name pattern is expanded into โ€ฆ Wikipedia
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Glob_(programming)
glob (programming) - Wikipedia
4 days ago - The original Mozilla proxy auto-config implementation, which provides a glob-matching function on strings, uses a replace-as-RegExp implementation as above. The bracket syntax happens to be covered by regex in such an example. Python's fnmatch uses a more elaborate procedure to transform the ...
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ glob-python
Python glob module: How to use glob function? (& glob vs iglob)
February 27, 2023 - The glob function will return a list of all filenames matching this pattern. Both the functions in Python's glob module are used to identify all file paths that match a given pattern.
๐ŸŒ
Real Python
realpython.com โ€บ ref โ€บ stdlib โ€บ glob
glob | Python Standard Library โ€“ Real Python
The Python glob module provides tools to find path names matching specified patterns that follow Unix shell rules.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ glob() in python
glob() in Python - Scaler Topics
May 4, 2023 - The term โ€œglobโ€ refers to methods for matching files that include specific patterns in line with UNIX shell-related expansion rules. In Python, the glob module is used similarly to find, locate, and search for all of the files that are present in a system.
๐ŸŒ
TechBeamers
techbeamers.com โ€บ python-glob
Python Glob Module Methods (with Patterns) - TechBeamers
December 30, 2025 - You can use the glob.escape() function to escape special characters in filenames. This is useful when you need to search for files with characters like โ€“ or # in their names. Pythonโ€™s glob module is a powerful tool for file pattern matching and directory traversal.
Find elsewhere
๐ŸŒ
Python Module of the Week
pymotw.com โ€บ 2 โ€บ glob
glob โ€“ Filename pattern matching - Python Module of the Week
import glob for name in glob.glob('dir/*'): print name ยท The pattern matches every pathname (file or directory) in the directory dir, without recursing further into subdirectories. $ python glob_asterisk.py dir/file.txt dir/file1.txt dir/file2.txt dir/filea.txt dir/fileb.txt dir/subdir
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
How to Use glob() in Python | note.nkmk.me
July 28, 2023 - In Python, the glob module allows you to get a list or an iterator of file and directory paths that satisfy certain conditions using special characters like the wildcard *. glob โ€” Unix style pathname ...
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_module_glob.asp
Python glob Module
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... import glob import tempfile import os with tempfile.TemporaryDirectory() as d: open(os.path.join(d, "Emil.txt"), "w").close() open(os.path.join(d, "Linus.txt"), "w").close() open(os.path.join(d, "Tobias.py"), "w").close() hits = glob.glob(os.path.join(d, "*.txt")) print(sorted(os.path.basename(x) for x in hits)) Try it Yourself ยป
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ how-to-use-glob-function-to-find-files-recursively-in-python
How to use Glob() Function to Find Files Recursively in Python - GeeksforGeeks
October 3, 2025 - Glob is a powerful pattern-matching technique widely used in Unix and Linux environments for matching file and directory names based on wildcard patterns. Pythonโ€™s built-in glob module provides similar functionality, enabling you to easily find files and directories matching specific patterns.
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ python glob: filename pattern matching
Python Glob: Filename Pattern Matching โ€“ PYnative
June 17, 2021 - But scandir() is a generator function that returns an iterator object. The glob() method instead returns a list that consumes a lot of memory. Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ which is much more efficient, glob.glob() or os.listdir()?
r/learnpython on Reddit: Which is much more efficient, glob.glob() or os.listdir()?
November 22, 2016 -

I am creating a program that requires scanning a directory for pdf files.

Do both functions have significant difference in processing speed especially when scanning a directory with a particular extension format?

Here are my two codes on how I use them both:

os.chdir("./")
for file in glob.glob("*.pdf"):
    convert_file_to_image(file)

And

for file in os.listdir("./"):
    if file.endswith(".pdf"):
        convert_file_to_image(file))

I believe when using the listdir() function can create more bandwidth requirement as I have a condition where it checks when the file ends in a certain format, compared with glob() wherein it accepts an argument before starting the loop, however I need to specify a chdir() before it starts.

๐ŸŒ
Earth Data Science
earthdatascience.org โ€บ home
Use the OS and Glob Python Packages to Manipulate File Paths | Earth Data Science - Earth Lab
November 12, 2020 - glob is a powerful tool in Python to help with file management and filtering.
๐ŸŒ
DEV Community
dev.to โ€บ 2320sharon โ€บ the-secrets-of-glob-31a7
The Secrets of Python's Glob - DEV Community
April 20, 2022 - import glob import os images_path=os.getcwd() + os.sep+"images" # C:\\Python\\images\\ glob_str=images_path+"*jpg" # C:\\Python\\images\\*jpg full_images_paths=glob.glob(glob_str) # On Windows Returns #["C:\\Python\\images\\img.jpg","C:\\Python\\images\\img2.jpg"]