Every directory in a posix-style filesystem features two files from the get go: .., which refers to the parent directory, and ., which refers to the current directory:

$ mkdir tmp; cd tmp
tmp cd .
tmp$  # <-- still in the same directory

- with the notable exception of /.., which refers to the root itself since the root has not parent.

A Path object from python's pathlib is, when it is created, just a wrapper around a string that is assumed to point somewhere into the filesystem. It will only refer to something tangible when it is resolved:

>>> Path('.')
PosixPath('.')  # just a fancy string
>>> Path('.').resolve()
PosixPath('/current/working/dir')  # an actual point in your filesystem

The bottom line is that

  • the paths /current/working/dir and /current/working/dir/. are, from the filesystem's point of view, completely equivalent, and
  • a pathlib.Path will also reflect that as soon as it is resolved.

By matching the glob call to ., you found all links pointing to the current directories below the initial directory. The results from glob get resolved on return, so the . doesn't appear in there any more.

As a source for this behavior, see this section of PEP428 (which serves as the specification for pathlib), where it briefly mentions path equivalence.

Answer from Arne on Stack Overflow
🌐
Python
docs.python.org › 3 › library › pathlib.html
pathlib — Object-oriented filesystem paths
In Path.glob() and rglob(), a trailing slash may be added to the pattern to match only directories.
🌐
GeeksforGeeks
geeksforgeeks.org › python › pathlib-module-in-python
Pathlib Module in Python - GeeksforGeeks
To find all Python files (.py) within a folder and its subfolders, use rglob() method from pathlib.
Published: June 15, 2026
🌐
PyPI
pypi.org › project › rglob
rglob · PyPI
Lightweight recursive search for Python, CLIs, and coding agents — globs, content grep, stat/dup helpers, JSON-stable outputs, typed agent API, optional MCP server.
🌐
Rednafi
rednafi.com › home › python › no really, python's pathlib is great
No really, Python's pathlib is great | Redowan's Reflections
June 30, 2026 - from contextlib import ExitStack from pathlib import Path # ExitStack ensures all files are properly closed after o/p with ExitStack() as stack: streams = ( stack.enter_context(open(fname, "r")) for fname in Path("src").rglob("*.py") ) contents = [f.read() for f in streams] print(contents)
🌐
Switowski
switowski.com › blog › pathlib
Pathlib for Path Manipulations - Sebastian Witowski
July 17, 2023 - def os_walk_files(): python_files = [] for root, dirs, files in os.walk("."): for filename in files: if filename.endswith(".py"): python_files.append(root + filename) return python_files · But it's much easier to use the glob module instead. That way we just need one line of code: import glob def glob_find_files(): glob.glob("./**/*.py", recursive=True) pathlib comes with a similar function called rglob().
🌐
Chris-piekarski
chris-piekarski.github.io › python-rglob
rglob
import rglob files = rglob.rglob("/path/to/project", "*.py") files_cwd = rglob.rglob_("*.py") lines = rglob.lcount( "/path/to/project", "*.py", lambda line: bool(line.strip()) and not line.lstrip().startswith("#"), ) mb = rglob.tsize("/path/to/photos", "*.jpg", rglob.megabytes)
🌐
GitHub
github.com › chris-piekarski › python-rglob › blob › master › README.md
python-rglob/README.md at master · chris-piekarski/python-rglob
For Python 2, the final supported version is 1.4 (links below). ... import rglob # List all Python files under a base directory files = rglob.rglob("/path/to/project", "*.py") # Same, starting from the current working directory files_cwd = rglob.rglob_("*.py") # Count non-empty, non-comment lines across matching files non_empty_non_comment = rglob.lcount( "/path/to/project", "*.py", lambda line: bool(line.strip()) and not line.lstrip().startswith("#"), ) # Total size of all JPGs in megabytes (use provided unit helpers) total_mb = rglob.tsize("/path/to/photos", "*.jpg", rglob.megabytes)
Author: chris-piekarski
Find elsewhere
🌐
Real Python
realpython.com › python-pathlib
Python's pathlib Module: Taming the File System – Real Python
3 days ago - If you want to recursively find all the files in both the directory and its subdirectories, then you can use .rglob().
🌐
PyTutorial
pytutorial.com › python-pathlib-rglob-explained
PyTutorial | Python Pathlib rglob() Explained
March 19, 2025 - The rglob() method in Python's pathlib module is a powerful tool for recursively searching for files and directories.
🌐
Chris-piekarski
chris-piekarski.github.io › python-rglob › api
API - rglob
>>> from rglob import find >>> list(find("/tmp", "*.txt")) >>> list(find("/tmp", ["*.py", "*.pyx"])) >>> list(find(".", "**/test_*.py"))
🌐
ZetCode
zetcode.com › python › pathlib
Python pathlib - working with files and directories in Python with pathlib
January 29, 2024 - for e in path.rglob('*.py'): print(e) # for e in path.glob('**/*.py'): # print(e) Both operations are equivalent. The following example is a practical program which outputs the contents of the specified directory in a hierarchical tree structure. tree.py · #!/usr/bin/python from pathlib import Path def tree(directory): print(f'+ {directory}') for path in sorted(directory.rglob('*')): depth = len(path.relative_to(directory).parts) spacer = ' ' * depth # print(f'{spacer}+ {path.name}') if path.is_file(): print(f'{spacer}f {path.name}') else: print(f'{spacer}d {path.name}') path = Path.home() / 'Downloads' tree(path) The program outputs the contents of the Downloads directory in a tree structure.
🌐
Runebook.dev
runebook.dev › en › docs › python › library › pathlib › pathlib.Path.rglob
python - From os.walk to rglob(): The Modern Way to Search Directories
The method Path.rglob(pattern) is a powerful tool in Python's standard library for recursively searching through a directory and all its subdirectories for files and directories that match a specific glob pattern.
🌐
DataCamp
datacamp.com › tutorial › comprehensive-tutorial-on-using-pathlib-in-python-for-file-system-manipulation
How to Use Python's Pathlib (with Examples) | DataCamp
May 22, 2024 - notebooks = articles_dir.rglob("*.ipynb") print(len(list(notebooks))) ... This time, our code found all 357 files. As we have seen, Path objects only represent files but don't perform operations on them. However, they do have certain methods for common file operations. We will see how to use them in this section. Reading file contents is a fundamental operation in many Python applications.
🌐
Real Python
realpython.com › lessons › listing-recursively-rglob
Listing Recursively With .rglob() (Video) – Real Python
So make sure you’re inside .rglob() and to pass in the argument you do two quotes and inside of those quotes a single asterisk.
Published: June 11, 2024
🌐
Chris-piekarski
chris-piekarski.github.io › python-rglob › cli
CLI - rglob
Quote glob patterns so your shell doesn't pre-expand them. Use rglob find "*.py", not rglob find *.py.
🌐
CodeRivers
coderivers.org › blog › python-pathlib-rglob-multiple-file-types
Working with Python pathlib's rglob for Multiple File Types - CodeRivers
August 8, 2026 - Use Generators: rglob returns a generator, so iterate over it directly instead of converting to a list. This saves memory when dealing with large directory trees: ```python # Good: iterate lazily for file in root_dir.rglob('*.txt'): process(file)