I had this same issue and wished glob.glob had an optional parameter to include dot files. I wanted to be able to include ALL dot files in ALL directories including directories that start with dot. Its just not possible to do this with glob.glob. However I found that Python has pathlib standard module which has a glob function which operates differently, it will include dot files. The function operates a little differently, in particular it does not return a list of strings, but instead path objects. However I used the following

files=[]
file_refs = pathlib.Path(".").glob(pattern)
for file in file_refs:
    files.append(str(file))

The other noticeable difference I found was a glob pattern ending with **. This returned nothing in the pathlib version but would return all the files in the glob.glob one. To get the same results I added a line to check if the pattern ended with ** and if so then append /* to it.

The following code is a replacement for your example that include the files in directories starting with dot

import pathlib
for fileref in pathlib.Path('/path/').glob('**/*.ext'):
    filename = str(fileref)
    print(filename)
Answer from waterjuice on Stack Overflow
🌐
Python
docs.python.org › 3 › library › glob.html
glob — Unix style pathname pattern expansion — Python 3.15.2 documentation
If recursive is true, the pattern “**” will match any files and zero or more directories, subdirectories and symbolic links to directories. If the pattern is followed by an os.sep or os.altsep then files will not match. If include_hidden is true, wildcards can match path segments that begin with a dot (.). Raises an auditing event glob.glob with arguments pathname, recursive.
🌐
Python
bugs.python.org › issue37578
Issue 37578: Change Glob: Allow Recursion for Hidden Files - Python tracker
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/81759
🌐
CSDN
devpress.csdn.net › python › 63045dfb7e6682346619a9ab.html
Python 3.6 glob include hidden files and folders_python_Mangs-Python
August 23, 2022 - import pathlib for fileref in pathlib.Path('/path/').glob('**/*.ext'): filename = str(fileref) print(filename)
🌐
TutorialsPoint
tutorialspoint.com › How-to-remove-hidden-files-and-folders-using-Python
How to remove hidden files and folders using Python?
Managing hidden files and folders in a directory is an essential part of building cleanup scripts or automation tools. On Windows, hidden files are not prefixed with a dot but instead they are marked using specific file attributes. In this article, w
🌐
Devgex
devgex.com › en › article › 00052044
Multiple Approaches to Ignore Hidden Files in Python and Their Implementation Principles - DevGex
December 11, 2025 - Abstract: This article provides an in-depth exploration of filtering hidden files when using the os.listdir() function in Python. By analyzing three main solutions—custom generator functions, glob module applications, and cross-platform hidden file detection methods—it explains the ...
🌐
YouTube
youtube.com › watch
Python's Path.glob() Secretly Skips Hidden Files - YouTube
Most developers assume pathlib.Path.glob('**/*.py') finds all Python files—including hidden ones—but it silently skips them. In this video you’ll see exactly...
Published: August 28, 2026
Find elsewhere
🌐
Python Forum
python-forum.io › thread-7459.html
How dont' show hidden system files
I'm using Windows now. I would like know how I can don't show hidden files in Windows. For example: import os print(os.listdir(r'C:/Users/mike/'))But I need to get only my files. How can I hide AppDat
🌐
YouTube
youtube.com › watch
Python glob('**/*.py') Misses Hidden Files—Fix in 6 Lines - YouTube
Most developers miss hidden Python files when using pathlib.glob('**/*.py'). Learn why—and how rglob('*') + filter fixes it cleanly. Subscribe for daily codi...
Published: September 16, 2026
🌐
TutorialsPoint
tutorialspoint.com › How-to-ignore-hidden-files-using-os-listdir-in-Python
How to ignore hidden files using os.listdir() in Python?
import os # List all non-hidden files visible_files = [file for file in os.listdir('.') if not file.startswith('.')] print(visible_files) ... ['Archive.zip', 'backup.tar', 'basic-calculator-program-using-python-program.htm', 'config.py', 'empty_file.txt', 'file1.txt', 'file2.txt', 'helper.py']
🌐
GitHub
gist.github.com › b6d337fec7011a0f9292
A glob.iglob that include dot files and hidden files · GitHub
September 13, 2020 - A glob.iglob that include dot files and hidden files - iglob_hidden.py
🌐
Python
bugs.python.org › issue26096
Issue 26096: '*' glob string matches dot files in pathlib - Python tracker
January 13, 2016 - This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/70284
🌐
YouTube
youtube.com › watch
Path.glob() Misses Hidden Files? Here's the 1-Line Fix - YouTube
Most developers miss hidden files with pathlib.Path.glob('**/*.py')—and it’s not a bug. This one-line fix using rglob('*') + filter gives you full control, i...
Published: September 11, 2026
🌐
Astral
docs.astral.sh › ruff › rules › glob
glob (PTH207) | Ruff - Astral Docs
import glob import os glob.glob(os.path.join("my_path", "requirements*.txt")) ... While using pathlib can improve the readability and type safety of your code, it can be less performant than the lower-level alternatives that work directly with strings, especially on older versions of Python.