Return an iterator which yields the paths matching a `pathname` pattern. The pattern may contain simple shell-style wildcards a la fnmatch. However, unlike fnmatch, filenames starting with a dot are special cases that are not matched by '*' and '?' patterns. The order of the re
(pathname, *, root_dir=None, dir_fd=None, recursive=False,
include_hidden=False)
| 44 | include_hidden=include_hidden)) |
| 45 | |
| 46 | def iglob(pathname, *, root_dir=None, dir_fd=None, recursive=False, |
| 47 | include_hidden=False): |
| 48 | """Return an iterator which yields the paths matching a `pathname` pattern. |
| 49 | |
| 50 | The pattern may contain simple shell-style wildcards a la |
| 51 | fnmatch. However, unlike fnmatch, filenames starting with a |
| 52 | dot are special cases that are not matched by '*' and '?' |
| 53 | patterns. |
| 54 | |
| 55 | The order of the returned paths is undefined. Sort them if you need a |
| 56 | particular order. |
| 57 | |
| 58 | If `root_dir` is not None, it should be a path-like object specifying |
| 59 | the root directory for searching. It has the same effect as changing |
| 60 | the current directory before calling it (without actually |
| 61 | changing it). If pathname is relative, the result will contain |
| 62 | paths relative to `root_dir`. |
| 63 | |
| 64 | If `dir_fd` is not None, it should be a file descriptor referring to a |
| 65 | directory, and paths will then be relative to that directory. |
| 66 | |
| 67 | If `include_hidden` is true, the patterns '*', '?', '**' will match hidden |
| 68 | directories. |
| 69 | |
| 70 | If `recursive` is true, the pattern '**' will match any files and |
| 71 | zero or more directories and subdirectories. |
| 72 | """ |
| 73 | sys.audit("glob.glob", pathname, recursive) |
| 74 | sys.audit("glob.glob/2", pathname, recursive, root_dir, dir_fd) |
| 75 | if root_dir is not None: |
| 76 | root_dir = os.fspath(root_dir) |
| 77 | else: |
| 78 | root_dir = pathname[:0] |
| 79 | it = _iglob(pathname, root_dir, dir_fd, recursive, False, |
| 80 | include_hidden=include_hidden) |
| 81 | if not pathname or recursive and _isrecursive(pathname[:2]): |
| 82 | try: |
| 83 | s = next(it) # skip empty string |
| 84 | if s: |
| 85 | it = itertools.chain((s,), it) |
| 86 | except StopIteration: |
| 87 | pass |
| 88 | return it |
| 89 | |
| 90 | def _iglob(pathname, root_dir, dir_fd, recursive, dironly, |
| 91 | include_hidden=False): |
no test coverage detected
searching dependent graphs…