Path.glob(pattern)
Glob the given pattern in the directory represented by this path, yielding all matching files (of any kind):
>>> sorted(Path('.').glob('*.py')) [PosixPath('pathlib.py'), PosixPath('setup.py'), PosixPath('test_pathlib.py')] >>> sorted(Path('.').glob('*/*.py')) [PosixPath('docs/conf.py')]
The “**
” pattern means “this directory and all subdirectories, recursively”. In other words, it enables recursive globbing:
>>> sorted(Path('.').glob('**/*.py')) [PosixPath('build/lib/pathlib.py'), PosixPath('docs/conf.py'), PosixPath('pathlib.py'), PosixPath('setup.py'), PosixPath('test_pathlib.py')]
Note
Using the “**
” pattern in large directory trees may consume an inordinate amount of time.
Please login to continue.