mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-03-24 10:33:28 +08:00
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.
This commit is contained in:
parent
382c20809b
commit
743599bd18
37
nodes.py
37
nodes.py
@ -1700,15 +1700,36 @@ class LoadImage:
|
|||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(s):
|
def INPUT_TYPES(s):
|
||||||
input_dir = folder_paths.get_input_directory()
|
input_dir = folder_paths.get_input_directory()
|
||||||
image_paths = []
|
files = []
|
||||||
for root, _, files in os.walk(input_dir, followlinks=True):
|
limit = 1000
|
||||||
image_files = folder_paths.filter_files_content_types(files, ["image"])
|
recursive_scan_failed = False
|
||||||
for image_file in image_files:
|
|
||||||
path_relative = os.path.relpath(os.path.join(root, image_file), input_dir)
|
# Attempt recursive scan first
|
||||||
path_relative = path_relative.replace('\\', '/')
|
try:
|
||||||
image_paths.append(path_relative)
|
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":
|
return {"required":
|
||||||
{"image": (sorted(list(set(image_paths))), {"image_upload": True})},
|
{"image": (sorted(list(dict.fromkeys(files))), {"image_upload": True})},
|
||||||
}
|
}
|
||||||
|
|
||||||
CATEGORY = "image"
|
CATEGORY = "image"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user