🌐
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
Why does this python's glob.glob method give an output when the parent directories do not exist?
What output does it give? Glob's output should be an empty list for a non-existing directory. Maybe there is something more at play here, post your actual code. (use pastebin.com if it is long) More on reddit.com
🌐 r/learnpython
5
1
July 31, 2023
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.
🌐
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
🌐
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.
Find elsewhere
🌐
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.
🌐
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 »
🌐
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 ...
🌐
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.
🌐
ChristopherGS
christophergs.com › python › 2017 › 01 › 01 › python-glob
Using Python glob
January 1, 2017 - The pattern rules for glob are not regular expressions.
🌐
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.
🌐
Netzro
netzro.github.io › posts › 2026 › Aug › 02 › globbing-in-python
Globbing in Python, Part 1
Glob returns strings, not sorted — the order is filesystem-dependent.
🌐
Michael Currin
michaelcurrin.github.io › dev-cheatsheets › cheatsheets › python › files-and-paths › glob.html
Glob | Dev Cheatsheets
Cheatsheets / Python / Files and paths / Glob · See also the globbing in the Shell section of this guide. glob in the Python 3 docs. From this StackOverflow page, where my answer was the highest voted. Provide a path as a single argument. You get results as absolute paths.