Nodes/TrentNodes/Text File Cowboy
ComfyUI Node

Text File Cowboy

Load one prompt file per clip, automatically

By TrentHunter82·Created 9 months ago·Updated 4 days ago· 36
Text File Cowboy
    • text
    • filename
    • total_files
    directory
    filename_key
    index0
    extension.txt
    index_modewrap

    If you've ever done per-clip rendering - a folder of 50 clips, each with its own prompt file - you know the pain: a batch loop that has to somehow pick the right text file for the right clip. Text File Cowboy is the TrentNodes answer, and it's part of a family (VideoFolderCowboy, ImageFolderCowboy, RefFolderCowboy) built around filename-keyed batch loading.

    The headline feature, straight from the README: wire VideoFolderCowboy's filename output into filename_key, and clip 000.mp4 automatically loads prompts/000.txt. The loop iterates, the right prompt rides along with the right video, and you never index-match anything by hand.

    How it works

    Give it a directory and it lists the text files there in natural sort order (the same vid1 < vid2 < vid10 ordering the other Cowboys use, so file 10 comes after file 2, not before). Then it picks one file by one of two routes:

    • filename_key (optional) - if connected, loads directory/<filename_key><extension>. This is the pairing magic.
    • index - a plain index into the sorted list, used only when filename_key isn't connected. index_mode controls overflow: wrap, clamp, or error.

    The extension input defaults to .txt - so you could point it at a folder of .md or .json prompt files without a second thought.

    Three outputs: text (the file contents - wire this into a CLIP text encode or wherever the prompt goes), filename (bare filename without extension, handy for downstream naming), and total_files (how many text files were found, so the loop knows its length).

    The detail that saves you actual time

    The README calls out that edits to the file bust the cache automatically via mtime. In ComfyUI's aggressive caching world, most file loaders will happily serve you a stale prompt until you restart or bypass something. Text File Cowboy watches the file's modification time, so you can tweak 023.txt in an editor and re-run - you get the new text without fighting the cache. That one behavior is worth the install by itself if you iterate on prompts a lot.

    Where this fits in a real pipeline

    The canonical setup, from the README's own framing:

    1. VideoFolderCowboy iterates the clips (natural sort, 000.mp4 first)
    2. Its filename output feeds TextFileCowboy's filename_key
    3. TextFileCowboy loads prompts/000.txt for that clip
    4. Text goes to the text encoder, video goes to the video path, frames render per-clip with per-clip prompts

    It also pairs with RefFolderCowboy if your per-clip pipeline includes reference images (refs/000/). Together they're the "per-clip render pipeline" the pack is built around.

    Gotchas

    • If filename_key is connected, index is ignored - wire one or the other, don't fight both.
    • wrap overflow silently loops back to the start, which is fine for testing and dangerous for a real batch you thought was length-checked. Use error mode when correctness beats convenience.
    • It reads one file at a time, not a whole directory into a list. If you want all files as a batch, that's a different node's job.

    Install

    One of ~69 nodes in TrentNodes:

    # ComfyUI Manager: search "Trent Nodes"
    
    # or:
    cd ComfyUI/custom_nodes
    git clone https://github.com/TrentHunter82/TrentNodes.git
    cd TrentNodes && pip install -r requirements.txt
    

    No extra dependencies or model downloads. It's the kind of node that reads as boring until you've hand-matched 40 clips to 40 prompts once, and then you never go back.

    CategoryTrent/Text

    Inputs (5)

    NameTypeDefaultDescription
    directorySTRINGDirectory containing the text files
    filename_keyoptSTRINGIf connected, load directory/<filename_key><extension>. Wire VideoFolderCowboy.filename here so clip 000.mp4 loads 000.txt
    indexoptINT00–999999Index into the natural-sorted file list (used only when filename_key is not connected)
    extensionoptSTRING.txtText file extension
    index_modeoptCOMBOwrapHow to handle index overflow

    Outputs (3)

    NameTypeDescription
    textSTRINGContents of the loaded text file
    filenameSTRINGFilename without extension
    total_filesINTTotal number of text files found