PyDocs

Nav

File and Directory Access

Path.glob

pathlib

method of Path (source)
  • Path.glob(pattern, *, case_sensitive=None, recurse_symlinks=False)
Iterate over this subtree and yield all existing files (of any
kind, including directories) matching the given relative pattern.
Changed in 3.12, 3.13
  • 3.12: The case_sensitive parameter was added.
  • 3.13: The recurse_symlinks parameter was added.
  • 3.13: The pattern parameter accepts a path-like object.
  • 3.13: Any OSError exceptions raised from scanning the filesystem are suppressed. In previous versions, such exceptions are suppressed in many cases, but not all.
1 Example
>>> sorted(Path('.').glob('*.py'))
[PosixPath('pathlib.py'), PosixPath('setup.py'), PosixPath('test_pathlib.py')]
>>> sorted(Path('.').glob('*/*.py'))
[PosixPath('docs/conf.py')]
>>> sorted(Path('.').glob('**/*.py'))
[PosixPath('build/lib/pathlib.py'),
 PosixPath('docs/conf.py'),
 PosixPath('pathlib.py'),
 PosixPath('setup.py'),
 PosixPath('test_pathlib.py')]
from the Python docs
See Also
No see-alsos for pathlib/Path.glob
0 Notes
No notes for Path.glob