# ====================================================================== # Node Pack: artyclaw-comfy # Author: artyclaw # Version: 1.0.0 # Description: A power-user toolkit for prompt logic, IO, and RNG. # ====================================================================== import os import glob from pathlib import Path class SimpleFolderParser: @classmethod def INPUT_TYPES(s): return { "required": { "folder_path": ("STRING", {"default": "C:/path/to/your/folder", "multiline": False}), "file_filter": ("STRING", {"default": "*.mp4", "multiline": False}), } } # We return two strings, but we will specify below that they are actually lists of strings RETURN_TYPES = ("STRING", "STRING") RETURN_NAMES = ("filenames_with_ext", "filenames_without_ext") # This tells ComfyUI to treat the outputs as a List/Batch, not a single string OUTPUT_IS_LIST = (True, True) FUNCTION = "parse_folder" CATEGORY = "utils/file" def parse_folder(self, folder_path, file_filter): # Safety check: does the folder exist? if not os.path.isdir(folder_path): print(f"[Warning] Simple Folder Parser: Directory '{folder_path}' does not exist.") return ([],[]) # Create the search pattern (e.g., C:/folder/*.mp4) search_pattern = os.path.join(folder_path, file_filter) # Use glob to find all matching paths matched_files = glob.glob(search_pattern) # Filter out directories just in case the wildcard matches a folder name matched_files =[f for f in matched_files if os.path.isfile(f)] # Sort alphabetically so the order is consistent every time you run it matched_files.sort() with_ext = [] without_ext =[] # Extract the parts of the filename for file_path in matched_files: path_obj = Path(file_path) with_ext.append(path_obj.name) # e.g., "video_01.mp4" without_ext.append(path_obj.stem) # e.g., "video_01" return (with_ext, without_ext) # Register the node in ComfyUI NODE_CLASS_MAPPINGS = { "SimpleFolderParser": SimpleFolderParser } NODE_DISPLAY_NAME_MAPPINGS = { "SimpleFolderParser": "Simple Folder Parser" } __all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS']