File Read
Read a whole text file into your graph — no pip install required
- text
- line_count
- success
File Read dumps a text file's entire contents into your graph as a string. It's the boring node you end up using constantly once you have it, because the modern ComfyUI workflow is full of places where the text you want shouldn't be baked into a widget - your prompt file, a system-prompt for an LLM node, a caption you keep editing on disk. Type the path, hit run, and the whole file arrives as text, ready to wire into a CLIPTextEncode or an LLM prompt input.
It comes from the Japanese-authored ComfyUI-String-Function pack, and the whole pack shares one nice property: it's pure Python stdlib. No requirements.txt, no model downloads, nothing heavy. File Read is a couple of hundred lines of open() under the hood, and that's the whole appeal.
How it works
The node reads the file with open(), optionally strips the trailing newline, and counts lines. The two details that save you real headaches:
- Encoding autodetection. Leave
encodingonautoand it triesutf-8-sig→utf-8→cp932(Shift-JIS), falling back to a lossyerrors="replace"read so it never crashes on a weird file. That covers the two classic text-file pain points: Windows Notepad's BOM, and Japanese-encoded files. - Path cleaning. If you paste a path with stray spaces or surrounding double quotes (the classic
"C:\prompts\hi.txt"from dragging out of Explorer), it strips them automatically.
The graceful failure is worth knowing: if the file doesn't exist, it doesn't throw and turn your whole graph red - it returns an empty string, line_count 0, and success False. Wire success into a switch or a String Default node and you can build a "file loaded or fallback" branch instead of babysitting errors.
Inputs and outputs
Only one input is required: file_path. The two you'll actually touch after that are encoding (auto is right for almost everyone) and strip_newline_end (leave it on unless you specifically want that trailing newline).
text(STRING) - the whole file. This is the one you wire into whatever's downstream.line_count(INT) - number of lines, useful for logging or splitting work.success(BOOLEAN) - True only if the file opened and decoded.
Installing it
No dependencies, no models, no API keys. Either search "ComfyUI-String-Function" in ComfyUI Manager, or do it by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/TakkunRed/ComfyUI-String-Function
Restart ComfyUI and look under String Function. It's MIT-licensed, and because there's no requirements.txt it can't drag you into dependency hell - genuinely one of the safest installs in the ecosystem.
Where people get burned
- It's cached. File Read doesn't override
IS_CHANGED, so if you edit the file on disk but nothing else in the graph changed, ComfyUI will happily hand you the stale cached contents. Bump any input (or toggle the node) to force a re-read. - The browse button is Windows-only. The little "📄 ファイルを参照..." button opens a dialog via PowerShell on the backend. On Linux or macOS it fails with an error - just type the full path into the widget.
- It reads the file fresh at run time, which is exactly what you want if your LLM node writes its output to disk first and File Read picks it up afterwards.
If you need one line at a time instead of the whole file, its sibling File Read Line does exactly that - and it's the more interesting node of the two.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| file_path | STRING | — | |
| encodingopt | COMBO | auto | 4 options: auto, utf-8, utf-8-sig, cp932 |
| strip_newline_endopt | BOOLEAN | true | ファイル末尾の改行を除去する |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| text | STRING | — |
| line_count | INT | — |
| success | BOOLEAN | — |