@@ -321,8 +321,6 @@ def walk(location, ignored=None, follow_symlinks=False):
321
321
If `follow_symlinks` is True, then symlinks will not be ignored and be
322
322
collected like regular files and directories
323
323
"""
324
- # TODO: consider using the new "scandir" module for some speed-up.
325
-
326
324
is_ignored = ignored (location ) if ignored else False
327
325
if is_ignored :
328
326
if TRACE :
@@ -335,13 +333,12 @@ def walk(location, ignored=None, follow_symlinks=False):
335
333
elif filetype .is_dir (location , follow_symlinks = follow_symlinks ):
336
334
dirs = []
337
335
files = []
338
- # TODO: consider using scandir
339
- for name in os .listdir (location ):
340
- loc = os .path .join (location , name )
336
+ for entry in os .scandir (location ):
337
+ loc = os .path .join (location , entry .name )
341
338
if filetype .is_special (loc ) or (ignored and ignored (loc )):
342
339
if (
343
340
follow_symlinks
344
- and filetype . is_link ( loc )
341
+ and entry . is_symlink ( )
345
342
and not filetype .is_broken_link (location )
346
343
):
347
344
pass
@@ -351,10 +348,10 @@ def walk(location, ignored=None, follow_symlinks=False):
351
348
logger_debug ("walk: ignored:" , loc , ign )
352
349
continue
353
350
# special files and symlinks are always ignored
354
- if filetype .is_dir (loc , follow_symlinks = follow_symlinks ):
355
- dirs .append (name )
356
- elif filetype .is_file (loc , follow_symlinks = follow_symlinks ):
357
- files .append (name )
351
+ if entry .is_dir (follow_symlinks = follow_symlinks ):
352
+ dirs .append (entry . name )
353
+ elif entry .is_file (follow_symlinks = follow_symlinks ):
354
+ files .append (entry . name )
358
355
yield location , dirs , files
359
356
360
357
for dr in dirs :
0 commit comments