Text File Cowboy
Load one prompt file per clip, automatically
- text
- filename
- total_files
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, loadsdirectory/<filename_key><extension>. This is the pairing magic.index- a plain index into the sorted list, used only whenfilename_keyisn't connected.index_modecontrols overflow:wrap,clamp, orerror.
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:
- VideoFolderCowboy iterates the clips (natural sort,
000.mp4first) - Its
filenameoutput feeds TextFileCowboy'sfilename_key - TextFileCowboy loads
prompts/000.txtfor that clip - 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_keyis connected,indexis ignored - wire one or the other, don't fight both. wrapoverflow silently loops back to the start, which is fine for testing and dangerous for a real batch you thought was length-checked. Useerrormode 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.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| directory | STRING | Directory containing the text files | |
| filename_keyopt | STRING | If connected, load directory/<filename_key><extension>. Wire VideoFolderCowboy.filename here so clip 000.mp4 loads 000.txt | |
| indexopt | INT | 00–999999 | Index into the natural-sorted file list (used only when filename_key is not connected) |
| extensionopt | STRING | .txt | Text file extension |
| index_modeopt | COMBO | wrap | How to handle index overflow |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| text | STRING | Contents of the loaded text file |
| filename | STRING | Filename without extension |
| total_files | INT | Total number of text files found |