Nodes/ComfyUI-Simple-Iterator/Iterator Load Text From Dir
ComfyUI Node

Iterator Load Text From Dir

A whole folder of prompts, served one at a time

By yangzhuangqiu·Created 5 months ago·Updated 5 months ago· 0
Iterator Load Text From Dir
    • TEXT
    • SOURCE_PATH
    • INDEX
    • TOTAL
    directory
    pattern*.txt,*.md,*.prompt,*.json,*.jsonl
    recursivefalse
    ordername_asc
    encodingutf-8
    loop_modestop
    resetfalse
    enable_logfalse

    Same pack, sibling node, opposite arrangement. IteratorLoadTextFromDir treats each file in a directory as one iteration item, where its cousin IteratorLoadTextFromFile splits a single file into many. If your prompts already live as separate .txt or .prompt files - maybe you keep a prompts folder per project, maybe you organize by asset - this is the one you reach for.

    How it works

    On each run it scans the directory with your glob pattern, sorts the hits, and returns one file's full contents per execution. Like every node in this pack, the cursor is persisted to .iterator_state.json in the plugin folder, scoped to the node id plus the directory and pattern - so the same folder feeding two different graphs keeps two independent cursors.

    The order argument is where the personality is. name_asc/name_desc for alphabetical, or mtime_asc/mtime_desc for file modification time. The mtime options are quietly the most useful: point it at a folder you keep adding to, set mtime_desc, and your newest prompt is always next.

    The inputs that matter

    • directory - where the files live.
    • pattern - comma or semicolon separated globs. Default is *.txt,*.md,*.prompt,*.json,*.jsonl.
    • recursive - default False. Flip it if your prompts hide in subfolders.
    • order - see above.
    • encoding - default utf-8. The reader uses errors="replace", so a mis-encoded file won't crash the run; it just comes out with replacement characters.
    • loop_mode / reset - pack-wide semantics: stop errors at the end, loop wraps, hold_last repeats the last item; reset only rewinds on a False→True edge.

    Outputs: TEXT (the whole file), SOURCE_PATH (full path, so you know exactly which file you're on), INDEX (0-based), TOTAL. Wire TEXT into your prompt encoding the way you would any string source.

    The natural workflow: a folder of prompts, this node on the positive prompt input, maybe a second one on a folder of negative prompts, then a batch of queue runs that walks through them while you inspect results between runs. Because each file is one item, SOURCE_PATH doubles as your "what am I looking at" label.

    Installing it

    Pack-wide install - ComfyUI Manager, search "ComfyUI-Simple-Iterator", or clone:

    cd ComfyUI/custom_nodes
    git clone https://github.com/yangzhuangqiu/ComfyUI-Simple-Iterator
    

    Restart ComfyUI after. The only direct dependencies are numpy and Pillow; torch is provided by your ComfyUI environment, so there's no big download.

    Where people get burned

    All the gotchas are about defaults. Forgot recursive and prompts in a subfolder/ never show up. Left pattern alone and anything outside the default five extensions - your .csv, your .srt - is silently ignored. And an exhausted iterator with stop raises instead of looping, which is exactly what you want for a batch job: it stops rather than quietly reprocessing your first prompt on the next run.

    Categorysimple_iterator

    Inputs (8)

    NameTypeDefaultDescription
    directorySTRING
    patternSTRING*.txt,*.md,*.prompt,*.json,*.jsonl
    recursiveBOOLEANfalse
    orderCOMBOname_asc4 options: name_asc, name_desc, mtime_asc, mtime_desc
    encodingSTRINGutf-8
    loop_modeCOMBOstop3 options: loop, stop, hold_last
    resetBOOLEANfalse
    enable_logoptBOOLEANfalse

    Outputs (4)

    NameTypeDescription
    TEXTSTRING
    SOURCE_PATHSTRING
    INDEXINT
    TOTALINT