Maybe there is a better way, but how about:

import glob
types = ('*.pdf', '*.cpp') # the tuple of file types
files_grabbed = []
for files in types:
    files_grabbed.extend(glob.glob(files))

# files_grabbed is the list of pdf and cpp files

Perhaps there is another way, so wait in case someone else comes up with a better answer.

Answer from user225312 on Stack Overflow
🌐
ELL Blog
blog.elijahlopez.ca › posts › python-glob-multiple-filetypes
Python Glob Multiple Filetypes - ELL's Blog - Elijah Lopez
February 2, 2024 - import glob FILE_EXTS = {'.txt', 'json'} def find_files(directory): for file in glob.iglob(f'{glob.escape(directory)}/**/*.*', recursive=True): if Path(uri).suffix.casefold() in FILE_EXTS: yield uri
People also ask

What is the best way to glob multiple file types in Python?
A: Using a custom function that combines globbing patterns or using libraries that extend the glob functionality can often yield the best results.
🌐
sqlpey.com
sqlpey.com › python › top-12-ways-to-use-python-glob-for-multiple-file-types
Top 12 Ways to Use Python Glob for Multiple File Types - …
Are there libraries to help with globbing in Python?
A: Yes, libraries like wcmatch extend the functionality of glob, allowing for more complex pattern matching capabilities.
🌐
sqlpey.com
sqlpey.com › python › top-12-ways-to-use-python-glob-for-multiple-file-types
Top 12 Ways to Use Python Glob for Multiple File Types - …
What is the difference between glob and pathlib?
A: glob is more pattern-based which means it is often used for file matching by patterns, while pathlib is object-oriented and provides an easier interface for handling filesystem paths.
🌐
sqlpey.com
sqlpey.com › python › top-12-ways-to-use-python-glob-for-multiple-file-types
Top 12 Ways to Use Python Glob for Multiple File Types - …
🌐
Python.org
discuss.python.org › ideas
Extended globbing through path names - Ideas - Discussions on Python.org
September 9, 2022 - As far as I’m aware there are two tools within the standard library that support globbing pathnames, glob and pathlib. Neither of these seem to support bash-style extended globbing or regex expression usage. Is there an…
🌐
GitHub
gist.github.com › elibroftw › 4599fb62d857bd5dce4040efc46e608d
Python get files of multiple extensions · GitHub
Python get files of multiple extensions · Raw · get_multiple_file_types.py · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Find elsewhere
🌐
PYnative
pynative.com › home › python › python glob: filename pattern matching
Python Glob: Filename Pattern Matching – PYnative
June 17, 2021 - Using the glob module we can search for exact file names or even specify part of it using the patterns created using wildcard characters. These patterns are similar to regular expressions but much simpler. ... We can specify a range of alphanumeric characters inside the []. We need to import Python’s built-in glob module to use the glob() function.
🌐
sqlpey
sqlpey.com › python › top-12-ways-to-use-python-glob-for-multiple-file-types
Top 12 Ways to Use Python Glob for Multiple File Types - …
December 5, 2024 - import itertools from glob import glob def multiple_file_types(*patterns): return itertools.chain.from_iterable(glob(p) for p in patterns) for filename in multiple_file_types("*.txt", "*.sql", "*.log"): print(filename) You can create a dynamic glob mask function that generates combined patterns based on the extensions you need:
🌐
Romain-clement
romain-clement.net › articles › python-pathlib-glob-patterns
Romain Clement - Python Pathlib complex glob patterns
September 18, 2023 - Today I learn Python pathlib.Path.glob does not support complex glob patterns such as *.{jpg,png}! Let's see how it can be done. First try: import pathlib mypath = pathlib.Path() / "tests" matched = list(mypath.glob("*.jpg")) + list(mypath.glob("*.png")) It does the job but I'm not a big fan of concataining lists as it allocates multiple list objects.
🌐
Sharp Coder Blog
sharpcoderblog.com › blog › how-to-use-pythons-glob-module-to-find-files-by-pattern
How to Use Python's glob Module to Find Files by Pattern | Sharp Coder Blog
September 4, 2024 - You can also use glob to find files with multiple extensions by using a pattern that includes multiple wildcard matches:
🌐
Python Module of the Week
pymotw.com › 2 › glob
glob – Filename pattern matching - Python Module of the Week
Now available for Python 3! Buy the book! ... Even though the glob API is very simple, the module packs a lot of power. It is useful in any situation where your program needs to look for a list of files on the filesystem with names matching a pattern. If you need a list of filenames that all have a certain extension...
🌐
Iditect
iditect.com › faq › python › pathlibpathglob-and-multiple-file-extension.html
pathlib.Path().glob() and multiple file extension
In Python's pathlib module, you can use the glob() method to search for files matching specific patterns. To match multiple file extensions using glob(), you can use wildcards to specify a pattern that includes those extensions.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-loop-through-files-of-certain-extensions
Python - Loop through files of certain extensions - GeeksforGeeks
July 23, 2025 - This method uses the Path() function from the pathlib module. The path function accepts the directory name as an argument and in glob function '**/*' pattern is used to find files of specific extensions.
🌐
Medium
medium.com › django-unleashed › python-file-handling-with-the-glob-module-a-comprehensive-guide-10b209fcbfbb
Python File Handling with the glob Module: A Comprehensive Guide | by Mehedi Khan | Django Unleashed | Medium
February 15, 2025 - The glob module is a part of Python's standard library and is used to find all the pathnames matching a specified pattern according to the rules used by the Unix shell. It’s especially useful for searching files with specific extensions, names, or patterns in a directory or across directories.