MCPcopy Index your code
hub / github.com/RustPython/RustPython / walk

Function walk

Lib/os.py:297–433  ·  view source on GitHub ↗

Directory tree generator. For each directory in the directory tree rooted at top (including top itself, but excluding '.' and '..'), yields a 3-tuple dirpath, dirnames, filenames dirpath is a string, the path to the directory. dirnames is a list of the names of the subdir

(top, topdown=True, onerror=None, followlinks=False)

Source from the content-addressed store, hash-verified

295_walk_symlinks_as_files = object()
296
297def walk(top, topdown=True, onerror=None, followlinks=False):
298 """Directory tree generator.
299
300 For each directory in the directory tree rooted at top (including top
301 itself, but excluding '.' and '..'), yields a 3-tuple
302
303 dirpath, dirnames, filenames
304
305 dirpath is a string, the path to the directory. dirnames is a list of
306 the names of the subdirectories in dirpath (including symlinks to directories,
307 and excluding '.' and '..').
308 filenames is a list of the names of the non-directory files in dirpath.
309 Note that the names in the lists are just names, with no path components.
310 To get a full path (which begins with top) to a file or directory in
311 dirpath, do os.path.join(dirpath, name).
312
313 If optional arg 'topdown' is true or not specified, the triple for a
314 directory is generated before the triples for any of its subdirectories
315 (directories are generated top down). If topdown is false, the triple
316 for a directory is generated after the triples for all of its
317 subdirectories (directories are generated bottom up).
318
319 When topdown is true, the caller can modify the dirnames list in-place
320 (e.g., via del or slice assignment), and walk will only recurse into the
321 subdirectories whose names remain in dirnames; this can be used to prune the
322 search, or to impose a specific order of visiting. Modifying dirnames when
323 topdown is false has no effect on the behavior of os.walk(), since the
324 directories in dirnames have already been generated by the time dirnames
325 itself is generated. No matter the value of topdown, the list of
326 subdirectories is retrieved before the tuples for the directory and its
327 subdirectories are generated.
328
329 By default errors from the os.scandir() call are ignored. If
330 optional arg 'onerror' is specified, it should be a function; it
331 will be called with one argument, an OSError instance. It can
332 report the error to continue with the walk, or raise the exception
333 to abort the walk. Note that the filename is available as the
334 filename attribute of the exception object.
335
336 By default, os.walk does not follow symbolic links to subdirectories on
337 systems that support them. In order to get this functionality, set the
338 optional argument 'followlinks' to true.
339
340 Caution: if you pass a relative pathname for top, don't change the
341 current working directory between resumptions of walk. walk never
342 changes the current directory, and assumes that the client doesn't
343 either.
344
345 Example:
346
347 import os
348 from os.path import join, getsize
349 for root, dirs, files in os.walk('python/Lib/xml'):
350 print(root, "consumes ")
351 print(sum(getsize(join(root, name)) for name in files), end=" ")
352 print("bytes in", len(files), "non-directory files")
353 if '__pycache__' in dirs:
354 dirs.remove('__pycache__') # don't visit __pycache__ directories

Callers 2

walkMethod · 0.50

Calls 12

isinstanceFunction · 0.85
scandirFunction · 0.85
reversedFunction · 0.85
islinkFunction · 0.85
fspathFunction · 0.70
onerrorFunction · 0.70
joinFunction · 0.70
popMethod · 0.45
is_dirMethod · 0.45
is_junctionMethod · 0.45
appendMethod · 0.45
is_symlinkMethod · 0.45

Tested by

no test coverage detected