Folder File Read
Read a different file every time you queue
- text
- file_name
- file_path_out
- file_index
- file_count
- is_last
Folder File Read is File Read Line's bigger sibling: instead of iterating over the lines of one text file, it iterates over the files in a folder, reading one whole file each time you run the graph, then wrapping around when it reaches the end. Point it at a folder of prompt files and queue the graph a few times and you're batch-testing across files with zero re-wiring. It's from the TakkunRed ComfyUI-String-Function pack, and like everything in that pack it's pure Python stdlib - no dependencies, no model downloads.
This is the node for the folder-shaped batch job: a pile of caption files you want to audit one by one, a directory of prompt variants, a set of config snippets for an LLM node. Line-by-line files don't fit that shape; files-in-a-folder do.
How it works
Mechanically it's the same always-rerun state machine as File Read Line: the node keeps an in-memory counter keyed to its own node instance, and its IS_CHANGED returns float("NaN") so ComfyUI re-executes it every run instead of caching it. Each run it returns the file at the current position and advances. sequential mode walks the sorted list and loops; shuffle consumes a random order without repeats and reshuffles when done.
The parts that make it actually pleasant to use:
extension_filter- default.txt, comma-separated for several (.txt,.md), and blank means all files in the folder. Filtering happens before counting, sofile_countreflects only what you'll actually read.sort_order-name_asc/name_descfor a stable alphabetical walk, ormodified_asc/modified_descto work through newest-or-oldest first. If you're processing a folder that grows as other nodes write into it, sorting by modified time is the sensible default.reset- feedTrueon a run and it jumps back to the first file that same run.- The counter is RAM-only. Restart ComfyUI and you start from the top; every node instance keeps its own independent counter.
Inputs and outputs
folder_path is the only required input. Beyond that: mode, reset, extension_filter, encoding (the same auto → utf-8-sig → utf-8 → cp932 chain as File Read), and sort_order.
The outputs are where the file-level iteration pays off:
text(STRING) - the current file's full contents. This is what feeds your encoder or LLM node.file_name(STRING) - just the filename, e.g.prompt_03.txt, great for afilename_prefixon SaveImage so each output is labeled.file_path_out(STRING) - the full path, useful if a downstream node wants to write a sibling file or save metadata alongside it.file_index(INT) /file_count(INT) - position and total.is_last(BOOLEAN) - True on the final file before the loop wraps.
Installing it
Search "ComfyUI-String-Function" in ComfyUI Manager, or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/TakkunRed/ComfyUI-String-Function
Restart ComfyUI and find it under String Function. MIT-licensed, zero third-party deps.
Where people get burned
- Same cache cost as File Read Line. The
NaNIS_CHANGEDforces a rerun every time, which also forces everything behind it to re-execute. Fine for a light graph; annoying if this sits in front of a heavy sampler - you'll want to isolate the iterative section. - Counters aren't persistent. Restart, and you're back at the first file.
- The folder picker button is Windows-only. The "📂 フォルダを参照..." button launches a PowerShell dialog on the backend; on Linux or macOS it errors, so type the path.
- One run = one file. Queue the graph N times to process N files in one go - the counter advances once per execution, not once per second.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| folder_path | STRING | — | |
| modeopt | COMBO | sequential | 2 options: sequential, shuffle |
| resetopt | BOOLEAN | false | True を受けた実行でカウンタをリセットし先頭から再開する |
| extension_filteropt | STRING | .txt | 対象拡張子(カンマ区切り例: .txt,.md)。空白で全ファイル |
| encodingopt | COMBO | auto | 4 options: auto, utf-8, utf-8-sig, cp932 |
| sort_orderopt | COMBO | name_asc | sequential モード時のファイル順序 |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| file_name | STRING | — |
| file_path_out | STRING | — |
| file_index | INT | — |
| file_count | INT | — |
| is_last | BOOLEAN | — |