Nodes/comfyui-grok-prompt-forge/Grok Text File Loader (Batch)
ComfyUI Node

Grok Text File Loader (Batch)

Crank a folder of ideas through your queue, one run at a time

By Slartibart23·Created 2 months ago·Updated a day ago· 1
Grok Text File Loader (Batch)
    • text
    • filename
    • file_path
    • total_files
    ◄folder_pathD:/captions►
    ◄index0►
    ◄pattern*.txt►
    ◄include_subfoldersfalse►
    ◄loop_at_endfalse►

    What this node is for

    Despite the name, this one doesn't touch the Grok API at all. It reads one .txt file per queue run, in order, from any folder on any drive. The author bundled it because the rest of the pack needs a supply of raw text and ComfyUI's built-in file loaders only see ComfyUI/input.

    You reach for it when you're doing the same thing many times. A folder of rough scene ideas that Grok Text Refine expands into prompts. A folder of pose or lighting fragments you want to cycle through for variety. A folder of raw captions you want to clean up and save back out under matching names. Anything where the interesting variable is "which text file" rather than "which seed."

    It's also the pack's answer to a real problem the wider LLM-in-a-graph workflow has: sampling dials add variation at the word level, but they can't stop the model reaching for the same golden-hour backdrop every time. Feeding genuinely different input text does that. Drop twenty scene fragments in a folder, set loop_at_end, and you've got an idea generator that doesn't repeat itself.

    How the batch actually works

    The index input is just an integer, and it's zero-indexed. The trick is the small control under it in the ComfyUI widget - set it to increment, set your queue batch count to the number of files, and hit queue. Each run loads the next file and quietly bumps index for you. That's the whole batch mechanism; there's no hidden loop.

    Files are sorted naturally, meaning file2.txt comes before file10.txt rather than after it (the node splits each filename on digit runs, so it's not the usual alphabetical file1, file10, file2 mess). If the index runs past the last file you get an error telling you how many files there were - unless loop_at_end is on, in which case it wraps back around to the first, which is what you want for endless variation.

    It also never caches. The node reports "changed" on every run, so dropping new files into the folder mid-session is picked up without a restart.

    The inputs worth setting: folder_path (absolute, any drive), pattern to grab a subset like pose_*.txt, include_subfolders if your files are nested, and loop_at_end.

    What comes out

    Four outputs, and they're more useful than they look:

    • text - the file contents, straight into Grok Text Refine's text input.
    • filename - the stem, no extension. This is the pairing trick: feed it to a save-text node's filename prefix and your outputs come back named to match their inputs, which matters a lot when you're processing 200 caption files.
    • file_path - the full path, handy for logging or for a second loader.
    • total_files - how many the pattern matched. Check this before you set your batch count.

    Install

    Search Grok Prompt Forge (xAI) in ComfyUI Manager, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Slartibart23/comfyui-grok-prompt-forge
    

    Restart and look under Grok → Text. Even though this node calls no API, it ships in the same pack, so the README's install steps are the ones that apply: requests, Pillow and numpy (all normally already present) and nothing else. You don't need an API key to use this node specifically - but the node you're almost certainly wiring it into does.

    Common issues

    "Index out of range." The single most common trip. You queued more runs than there are files, or forgot that it's zero-indexed and that your batch count should equal total_files, not total_files + 1. The error message tells you the total, so you don't have to guess.

    "Folder not found" or "No files matching." folder_path has to be a real absolute path, and the default D:/captions is a placeholder, not a suggestion. If the folder exists but the pattern matches nothing, check that you didn't restrict it to something like pose_*.txt while your files are named differently.

    Encoding. This loader is friendly - it tries utf-8-sig, utf-8, cp1252 and latin-1 before giving up, so files saved by an old Windows Notepad won't choke it.

    "I changed the text but nothing changed." The loader itself never caches, so look downstream. The API nodes are only re-executed when an input changes, and seed is their cache-breaker - leave it on fixed and identical inputs return the cached result.

    CategoryGrok/Text

    Inputs (5)

    NameTypeDefaultDescription
    folder_pathSTRINGD:/captionsFolder to load text files from. Any drive, absolute path. Files are sorted naturally (file2 before file10).
    indexINT00–999999Which file to load (0 = first). Set the control below to 'increment' and queue a batch count equal to the number of files - each run loads the next file automatically.
    patternSTRING*.txtFilename filter, e.g. *.txt for all text files or pose_*.txt for a specific subset.
    include_subfoldersBOOLEANfalseAlso search all subfolders of folder_path.
    loop_at_endBOOLEANfalseWhen the index passes the last file, wrap around to the first instead of stopping with an error. Useful for endless wildcard-style cycling through scene ideas.

    Outputs (4)

    NameTypeDescription
    textSTRING—
    filenameSTRING—
    file_pathSTRING—
    total_filesINT—