Commits

Antoine Pitrou committed 456d24b

Add docs

  • Participants
  • Parent commits d252d7a

Comments (0)

Files changed (2)

 Listing Python source files in a directory::
 
     >>> p = Path('.')
-    >>> [x for x in p if x.ext == '.py']
+    >>> list(p.glob('*.py'))
     [PosixPath('test_pathlib.py'), PosixPath('setup.py'),
      PosixPath('pathlib.py')]
 
+Listing all Python source files in this directory tree::
+
+    >>> list(p.glob('**/*.py'))
+    [PosixPath('test_pathlib.py'), PosixPath('setup.py'),
+     PosixPath('pathlib.py'), PosixPath('docs/conf.py'),
+     PosixPath('build/lib/pathlib.py')]
+
 Listing subdirectories::
 
     >>> [x for x in p if x.is_dir()]
 Version 0.7
 ^^^^^^^^^^^
 
+- Add '**' (recursive) patterns to Path.glob().
 - Fix openat() support after the API refactoring in Python 3.3 beta1.
 - Add a *target_is_directory* argument to Path.symlink_to()
 
       >>> 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.
+
 
 .. method:: Path.is_dir()
 
 
 .. method:: Path.rglob(pattern)
 
-   Like :meth:`glob`, but glob recursively from any subdirectories as well::
+   This is like calling :meth:`glob` with "``**``" added in front of the
+   given *pattern*:
 
       >>> sorted(Path().rglob("*.py"))
       [PosixPath('build/lib/pathlib.py'),