Nodes/ComfyUI-K3NKImageGrab/Load Text From Dir (K3NK)
ComfyUI Node

Load Text From Dir (K3NK)

Load Text From a Folder

By K3NK3·Created 9 months ago·Updated 2 months ago· 8
Load Text From Dir (K3NK)
    • text
    • index
    • total_files
    • filename
    directory
    sort_method
    start_index0
    load_alwaysfalse
    encoding

    If you've ever wanted to run the same workflow against fifty different prompts without editing a text box fifty times, you know the manual grind: change prompt, queue, wait, change prompt again. Load Text From Dir (K3NK) is the laziest possible fix - it reads a .txt file from a folder by index, so you can point one graph at a directory of prompt files and step through them like slides.

    It's a small utility, and it's honest about being one. But it slots into exactly two workflow shapes that are genuinely useful: batch iteration (prompt per file, bump start_index between runs) and keeping your prompt library as plain text files instead of baked into the graph where they're invisible and un-greppable. For anyone who version-controls their prompting, that second one is a quiet quality-of-life win.

    How it works

    Point it at a directory, it lists every .txt file, sorts it according to your sort_method, and loads the one at start_index. Outputs are the full file contents plus three useful metadata values: the current index, how many files exist (total_files), and the loaded filename. That last trio matters more than it looks - you can wire total_files into a range loop or a text display so you always know where you are in the batch.

    The sort_method enum is the part to read carefully, because batch order is the whole point: None, Alphabetical (ASC/DESC), Numerical (ASC/DESC), or Datetime (ASC/DESC). Numerical sorts by the number embedded in the filename (prompt_01.txt before prompt_10.txt), which is what you want for files with zero-padded counters. Datetime sorts by file modification time - handy if you're appending to files rather than renaming them.

    encoding defaults to utf-8, with utf-8-sig (strips BOM, useful for files saved by Windows Notepad), latin-1, and cp1252 as fallbacks. If you're hitting mojibake, try utf-8-sig before anything else - it's the classic culprit.

    load_always (default off) forces the node to re-read on every run. Leave it off when you want ComfyUI's caching to skip the node for unchanged inputs; flip it on when you're editing prompt files live and want each queue to pick up the latest version.

    Installing it

    Part of the K3NK pack. ComfyUI Manager → search ComfyUI-K3NKImageGrab, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/K3NK3/ComfyUI-K3NKImageGrab
    

    Restart ComfyUI. Pure Python - no extra dependencies.

    Where people get burned

    The classic footgun is start_index out of range: the node raises an error rather than clamping, so if you deleted a file mid-batch you'll get a hard failure instead of a shrug. The other one is mixing sort modes without thinking - a batch sorted alphabetically will put prompt_10.txt before prompt_2.txt, which is wrong in most batch setups; pick Numerical and pad your filenames. Minor note: the tooltips are in Spanish (Índice del archivo a cargar), which is a giveaway the author's native workflow language is Spanish - the inputs behave identically, but don't be surprised when you hover and get a foreign-language hint.

    CategoryK3NK/loaders

    Inputs (5)

    NameTypeDefaultDescription
    directorySTRING
    sort_methodCOMBO7 options: None, Alphabetical (ASC), Alphabetical (DESC), Numerical (ASC), Numerical (DESC), Datetime (ASC), +1
    start_indexoptINT00–99999Índice del archivo a cargar
    load_alwaysoptBOOLEANfalse
    encodingoptCOMBO4 options: utf-8, utf-8-sig, latin-1, cp1252

    Outputs (4)

    NameTypeDescription
    textSTRING
    indexINT
    total_filesINT
    filenameSTRING