From ff5a74f31d70b6d64bdc3cb2cddb9b594e3447dc Mon Sep 17 00:00:00 2001 From: hetima <33700+hetima@users.noreply.github.com> Date: Sat, 14 Mar 2026 13:37:42 +0900 Subject: [PATCH] SLPDirectoryContents --- __init__.py | 3 +++ slp_directory_list.py | 57 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 slp_directory_list.py diff --git a/__init__.py b/__init__.py index a52a66b..c4ba5d9 100644 --- a/__init__.py +++ b/__init__.py @@ -1,12 +1,14 @@ from .single_line_picker import SLPSingleLinePicker from .slp_lora_loader import SLPLoraLoader, SLPLoraLoaderModelOnly from .slp_filename_prefix import SLPFilenamePrefix +from .slp_directory_list import SLPDirectoryContents NODE_CLASS_MAPPINGS = { SLPSingleLinePicker.NAME: SLPSingleLinePicker, SLPLoraLoader.NAME: SLPLoraLoader, SLPLoraLoaderModelOnly.NAME: SLPLoraLoaderModelOnly, SLPFilenamePrefix.NAME: SLPFilenamePrefix, + SLPDirectoryContents.NAME: SLPDirectoryContents } NODE_DISPLAY_NAME_MAPPINGS = { @@ -14,6 +16,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { SLPLoraLoader.NAME: SLPLoraLoader.DISPLAY_NAME, SLPLoraLoaderModelOnly.NAME: SLPLoraLoaderModelOnly.DISPLAY_NAME, SLPFilenamePrefix.NAME: SLPFilenamePrefix.DISPLAY_NAME, + SLPDirectoryContents.NAME: SLPDirectoryContents.DISPLAY_NAME, } diff --git a/slp_directory_list.py b/slp_directory_list.py new file mode 100644 index 0000000..71b733c --- /dev/null +++ b/slp_directory_list.py @@ -0,0 +1,57 @@ +from pathlib import Path + +class SLPDirectoryContents: + NAME = "HetimaSLPDirectoryContents" + DISPLAY_NAME = "SLP Directory Contents" + + CATEGORY = "SingleLinePicker" + DESCRIPTION = "Outputs the contents of the directory." + + # 毎回読み込む + @classmethod + def IS_CHANGED(cls): + return float("NaN") + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "path": ("STRING", {"multiline": False, "default": "", "tooltip": 'Path to directory'}), + "is_full_path": ("BOOLEAN", {"default": True, "tooltip": "Outputs as full path"}), + "SLP_format": ("BOOLEAN", {"default": False, "tooltip": "Outputs for SLP List View"}), + "prefix": ("STRING", {"multiline": False, "default": "", "tooltip": "Prefix for each output path"}), + }, + "optional": { + }, + } + + RETURN_TYPES = ("STRING",) + RETURN_NAMES = ("STRING",) + OUTPUT_TOOLTIPS = ("directory contents",) + OUTPUT_NODE = True + FUNCTION = "execute" + + def execute(self, path="", is_full_path=True, SLP_format=False, prefix=""): + dir_path = Path(path) + if not path or not dir_path.is_dir(): + return ("",) + + files = sorted([f for f in dir_path.iterdir()]) + result_prefix = "" + if SLP_format: + result_prefix = "#dict\n" + results = [] + for file in files: + path_str = "" + if is_full_path: + path_str = str(file.resolve()) + else: + path_str = file.name + if prefix != "": + path_str = prefix + path_str + if SLP_format: + path_str = file.name + ":" + path_str + + results.append(path_str) + + return (result_prefix + "\n".join(results),)