MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _iterdir

Function _iterdir

tools/python-3.11.9-amd64/Lib/glob.py:142–174  ·  view source on GitHub ↗
(dirname, dir_fd, dironly)

Source from the content-addressed store, hash-verified

140# If dironly is false, yields all file names inside a directory.
141# If dironly is true, yields only directory names.
142def _iterdir(dirname, dir_fd, dironly):
143 try:
144 fd = None
145 fsencode = None
146 if dir_fd is not None:
147 if dirname:
148 fd = arg = os.open(dirname, _dir_open_flags, dir_fd=dir_fd)
149 else:
150 arg = dir_fd
151 if isinstance(dirname, bytes):
152 fsencode = os.fsencode
153 elif dirname:
154 arg = dirname
155 elif isinstance(dirname, bytes):
156 arg = bytes(os.curdir, 'ASCII')
157 else:
158 arg = os.curdir
159 try:
160 with os.scandir(arg) as it:
161 for entry in it:
162 try:
163 if not dironly or entry.is_dir():
164 if fsencode is not None:
165 yield fsencode(entry.name)
166 else:
167 yield entry.name
168 except OSError:
169 pass
170 finally:
171 if fd is not None:
172 os.close(fd)
173 except OSError:
174 return
175
176def _listdir(dirname, dir_fd, dironly):
177 with contextlib.closing(_iterdir(dirname, dir_fd, dironly)) as it:

Callers 1

_listdirFunction · 0.85

Calls 4

fsencodeFunction · 0.70
openMethod · 0.45
is_dirMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected