diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2020-06-18 19:08:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-18 19:08:27 (GMT) |
commit | 8a64ceaf9856e7570cad6f5d628cce789834e019 (patch) | |
tree | a8744955bcf190b98b8d0d87b1eaa60620013c3f /Doc | |
parent | 8f192d12af82c4dc40730bf59814f6a68f68f950 (diff) | |
download | cpython-8a64ceaf9856e7570cad6f5d628cce789834e019.zip cpython-8a64ceaf9856e7570cad6f5d628cce789834e019.tar.gz cpython-8a64ceaf9856e7570cad6f5d628cce789834e019.tar.bz2 |
bpo-38144: Add the root_dir and dir_fd parameters in glob.glob(). (GH-16075)
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/glob.rst | 16 | ||||
-rw-r--r-- | Doc/whatsnew/3.10.rst | 8 |
2 files changed, 22 insertions, 2 deletions
diff --git a/Doc/library/glob.rst b/Doc/library/glob.rst index 92a8c4d..280e9f0 100644 --- a/Doc/library/glob.rst +++ b/Doc/library/glob.rst @@ -36,7 +36,7 @@ For example, ``'[?]'`` matches the character ``'?'``. The :mod:`pathlib` module offers high-level path objects. -.. function:: glob(pathname, *, recursive=False) +.. function:: glob(pathname, *, root_dir=None, dir_fd=None, recursive=False) Return a possibly-empty list of path names that match *pathname*, which must be a string containing a path specification. *pathname* can be either absolute @@ -45,6 +45,15 @@ For example, ``'[?]'`` matches the character ``'?'``. symlinks are included in the results (as in the shell). Whether or not the results are sorted depends on the file system. + If *root_dir* is not ``None``, it should be a :term:`path-like object` + specifying the root directory for searching. It has the same effect on + :func:`glob` as changing the current directory before calling it. If + *pathname* is relative, the result will contain paths relative to + *root_dir*. + + This function can support :ref:`paths relative to directory descriptors + <dir_fd>` with the *dir_fd* parameter. + .. index:: single: **; in glob-style wildcards @@ -62,8 +71,11 @@ For example, ``'[?]'`` matches the character ``'?'``. .. versionchanged:: 3.5 Support for recursive globs using "``**``". + .. versionchanged:: 3.10 + Added the *root_dir* and *dir_fd* parameters. + -.. function:: iglob(pathname, *, recursive=False) +.. function:: iglob(pathname, *, root_dir=None, dir_fd=None, recursive=False) Return an :term:`iterator` which yields the same values as :func:`glob` without actually storing them all simultaneously. diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index f956ddd..566827b 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -100,6 +100,14 @@ New Modules Improved Modules ================ +glob +---- + +Added the *root_dir* and *dir_fd* parameters in :func:`~glob.glob` and +:func:`~glob.iglob` which allow to specify the root directory for searching. +(Contributed by Serhiy Storchaka in :issue:`38144`.) + + Optimizations ============= |