Browse Source

feat: Add support for excluded_dirs to folder_paths.recursive_search

Refactored variable names to better match what they represent
pull/1312/head
Michael Poutre 1 year ago
parent
commit
d196847079
No known key found for this signature in database
GPG Key ID: ACEAC6CFD77EB15E
  1. 21
      folder_paths.py

21
folder_paths.py

@ -121,18 +121,25 @@ def add_model_folder_path(folder_name, full_folder_path):
def get_folder_paths(folder_name): def get_folder_paths(folder_name):
return folder_names_and_paths[folder_name][0][:] return folder_names_and_paths[folder_name][0][:]
def recursive_search(directory): def recursive_search(directory, excluded_dir_names=None):
if not os.path.isdir(directory): if not os.path.isdir(directory):
return [], {} return [], {}
if excluded_dir_names is None:
excluded_dir_names = []
result = [] result = []
dirs = {directory: os.path.getmtime(directory)} dirs = {directory: os.path.getmtime(directory)}
for root, subdir, file in os.walk(directory, followlinks=True): for dirpath, subdirs, filenames in os.walk(directory, followlinks=True, topdown=True):
for filepath in file: print("Checking directory: " + dirpath)
#we os.path,join directory with a blank string to generate a path separator at the end. subdirs[:] = [d for d in subdirs if d not in excluded_dir_names]
result.append(os.path.join(root, filepath).replace(os.path.join(directory,''),'')) for file_name in filenames:
for d in subdir: relative_path = os.path.relpath(os.path.join(dirpath, file_name), directory)
path = os.path.join(root, d) result.append(relative_path)
for d in subdirs:
path = os.path.join(dirpath, d)
dirs[path] = os.path.getmtime(path) dirs[path] = os.path.getmtime(path)
print("Returning from recursive_search" + repr(result))
return result, dirs return result, dirs
def filter_files_extensions(files, extensions): def filter_files_extensions(files, extensions):

Loading…
Cancel
Save