Skip to content

Commit 8510576

Browse files
committed
GH-101112: Provide pattern overview for Path.glob
Unlike previously stated, the patterns used for `Path.glob`, `Path.rglob` and `Path.match` do not behave like the ones for `fnmatch`. Remove the refernce to `fnmatch` and provide an overview of the available patterns.
1 parent 3325f05 commit 8510576

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

Doc/library/pathlib.rst

+22-5
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ Pure paths provide the following methods and properties:
574574
>>> PureWindowsPath('b.py').match('*.PY')
575575
True
576576

577+
For an overview of available patterns see :meth:`Path.glob`, with the
578+
exception that "``**``" behaves just like "``*``".
577579

578580
.. method:: PurePath.relative_to(other, walk_up=False)
579581

@@ -861,9 +863,7 @@ call fails (for example because the path doesn't exist).
861863
>>> sorted(Path('.').glob('*/*.py'))
862864
[PosixPath('docs/conf.py')]
863865

864-
Patterns are the same as for :mod:`fnmatch`, with the addition of "``**``"
865-
which means "this directory and all subdirectories, recursively". In other
866-
words, it enables recursive globbing::
866+
"``**``" enables recursive globbing::
867867

868868
>>> sorted(Path('.').glob('**/*.py'))
869869
[PosixPath('build/lib/pathlib.py'),
@@ -872,6 +872,22 @@ call fails (for example because the path doesn't exist).
872872
PosixPath('setup.py'),
873873
PosixPath('test_pathlib.py')]
874874

875+
The following wildcards are available:
876+
877+
+------------+------------------------------------+
878+
| Pattern | Meaning |
879+
+============+====================================+
880+
| ``**`` | matches everything, recursively |
881+
+------------+------------------------------------+
882+
| ``*`` | matches everything |
883+
+------------+------------------------------------+
884+
| ``?`` | matches any single character |
885+
+------------+------------------------------------+
886+
| ``[seq]`` | matches any character in *seq* |
887+
+------------+------------------------------------+
888+
| ``[!seq]`` | matches any character not in *seq* |
889+
+------------+------------------------------------+
890+
875891
.. note::
876892
Using the "``**``" pattern in large directory trees may consume
877893
an inordinate amount of time.
@@ -1270,8 +1286,7 @@ call fails (for example because the path doesn't exist).
12701286
.. method:: Path.rglob(pattern)
12711287

12721288
Glob the given relative *pattern* recursively. This is like calling
1273-
:func:`Path.glob` with "``**/``" added in front of the *pattern*, where
1274-
*patterns* are the same as for :mod:`fnmatch`::
1289+
:func:`Path.glob` with "``**/``" added in front of the *pattern*::
12751290

12761291
>>> sorted(Path().rglob("*.py"))
12771292
[PosixPath('build/lib/pathlib.py'),
@@ -1280,6 +1295,8 @@ call fails (for example because the path doesn't exist).
12801295
PosixPath('setup.py'),
12811296
PosixPath('test_pathlib.py')]
12821297

1298+
For an overview of available patterns see :meth:`Path.glob`.
1299+
12831300
.. audit-event:: pathlib.Path.rglob self,pattern pathlib.Path.rglob
12841301

12851302
.. versionchanged:: 3.11

0 commit comments

Comments
 (0)