From 743599bd189e9cdfae2abbb3856d3520324e1247 Mon Sep 17 00:00:00 2001 From: molbal Date: Sun, 8 Feb 2026 22:42:37 +0100 Subject: [PATCH] Enhance LoadImage to support recursive file scanning Updated the LoadImage class to implement a recursive scan for image files with a limit and fallback to a non-recursive method if necessary. --- nodes.py | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/nodes.py b/nodes.py index cd2b870b7..2485a26b7 100644 --- a/nodes.py +++ b/nodes.py @@ -1700,15 +1700,36 @@ class LoadImage: @classmethod def INPUT_TYPES(s): input_dir = folder_paths.get_input_directory() - image_paths = [] - for root, _, files in os.walk(input_dir, followlinks=True): - image_files = folder_paths.filter_files_content_types(files, ["image"]) - for image_file in image_files: - path_relative = os.path.relpath(os.path.join(root, image_file), input_dir) - path_relative = path_relative.replace('\\', '/') - image_paths.append(path_relative) + files = [] + limit = 1000 + recursive_scan_failed = False + + # Attempt recursive scan first + try: + for root, _, file_list in os.walk(input_dir, followlinks=False): + if recursive_scan_failed: + break + + image_files = folder_paths.filter_files_content_types(file_list, ["image"]) + + for image_file in image_files: + if len(files) >= limit: + recursive_scan_failed = True + break + + path_relative = os.path.relpath(os.path.join(root, image_file), input_dir) + path_relative = path_relative.replace('\\', '/') + files.append(path_relative) + except Exception: + recursive_scan_failed = True + + # Fallback to original non-recursive method if limit exceeded or error + if recursive_scan_failed or not files: + files = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f))] + files = folder_paths.filter_files_content_types(files, ["image"]) + return {"required": - {"image": (sorted(list(set(image_paths))), {"image_upload": True})}, + {"image": (sorted(list(dict.fromkeys(files))), {"image_upload": True})}, } CATEGORY = "image"