From 6a63454f6257b87b21ec61beadfb6d8efc838c93 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 3 Feb 2020 16:43:39 -0800 Subject: [PATCH] Fix exclude_directories not being used because if yield_dirs. --- voussoirkit/spinal.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/voussoirkit/spinal.py b/voussoirkit/spinal.py index cbac41b..9440cd6 100644 --- a/voussoirkit/spinal.py +++ b/voussoirkit/spinal.py @@ -684,13 +684,19 @@ def walk_generator( yield (current_location, directories, files) def walkstep_flat(current_location, child_dirs, child_files): - if yield_directories: - for child_dir in child_dirs: - child_dir_abspath = f'{current_location}{os.sep}{child_dir}' - if handle_exclusion(exclude_directories, child_dir, child_dir_abspath, 'directory'): - continue + new_child_dirs = [] + for child_dir in child_dirs: + child_dir_abspath = f'{current_location}{os.sep}{child_dir}' + if handle_exclusion(exclude_directories, child_dir, child_dir_abspath, 'directory'): + continue + + new_child_dirs.append(child_dir) + if yield_directories: yield pathclass.Path(child_dir_abspath) + # This will actually affect the results of the os.walk going forward! + child_dirs[:] = new_child_dirs + if yield_files: for child_file in child_files: child_file_abspath = f'{current_location}{os.sep}{child_file}'