From 0a9feb3f909441881e65a1f17d5bd50f40a75209 Mon Sep 17 00:00:00 2001 From: parlt Date: Wed, 19 Jun 2024 11:20:08 +0200 Subject: [PATCH] #3783 Extra Models Configuration with subfolders If you want to use web ui models in Comfy Ui and for structural reasons have structured the checkpoints, VAE etc in the Web Ui models folder in subfolders, these are not recognized by Comfy Ui. It would be desirable if ComfyUI would also recognize subfolders f.e. Extra Models Folder -> Checkpoints -> SD 1.5, SD 2.1, SD 3 Medium --- folder_paths.py | 12 +++++++++++- main.py | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/folder_paths.py b/folder_paths.py index 234b73409..4e83b6ffb 100644 --- a/folder_paths.py +++ b/folder_paths.py @@ -126,10 +126,20 @@ def exists_annotated_filepath(name): def add_model_folder_path(folder_name, full_folder_path): global folder_names_and_paths if folder_name in folder_names_and_paths: - folder_names_and_paths[folder_name][0].append(full_folder_path) + subdirs = list_files(full_folder_path) + if len(subdirs) == 0: + folder_names_and_paths[folder_name][0].append(full_folder_path) + else: + for subdir in subdirs: + folder_names_and_paths[folder_name][0].append(subdir) + else: folder_names_and_paths[folder_name] = ([full_folder_path], set()) +def list_files(dir): + r = [] + return [x[0] for x in os.walk(dir)] + def get_folder_paths(folder_name): return folder_names_and_paths[folder_name][0][:] diff --git a/main.py b/main.py index a374f2b12..719b4f9bc 100644 --- a/main.py +++ b/main.py @@ -184,6 +184,8 @@ def load_extra_path_config(yaml_path): if base_path is not None: full_path = os.path.join(base_path, full_path) logging.info("Adding extra search path {} {}".format(x, full_path)) + full_path = full_path.replace("\\", "\\") + full_path = full_path.replace("\\", "/") folder_paths.add_model_folder_path(x, full_path)