Nodes/Comfyui-PixNodes/Load Text from Folder (PixNodes)
ComfyUI Node

Load Text from Folder (PixNodes)

Load a prompt from a folder of .txt files by index

By pixixai·Created 8 months ago·Updated 5 months ago· 23
Load Text from Folder (PixNodes)
    • content
    • file_name
    • index
    • total_files
    directory/path/to/txt/files
    start_index0

    The classic batch-generation setup: a folder full of prompts, one per .txt file, and you want each generation to pull the next one. Load Text from Folder is the node that bridges that folder to your graph - point it at a directory, give it an index, and it returns the file's contents plus the filename and some bookkeeping numbers that make the loop work.

    It's a deliberately narrow tool, and that's its strength. No wildcard resolution, no recursive scanning, no encoding sniffing - it reads .txt files from one directory in sorted order and hands you one of them. Everything you'd bolt onto it (loops, batch iteration, random selection) belongs outside this node, in the graph around it.

    How the selection works

    The inputs are directory (a path string, default /path/to/txt/files) and start_index (INT, default 0). At execution it lists every *.txt in the folder and sorts them with natural sort - meaning file2.txt sorts before file10.txt, which the default lexicographic sort gets backwards. That's the detail that saves a batch workflow from processing prompts out of order.

    The output is four ports: content (STRING, the file's text), file_name (STRING, without the .txt extension), index (INT, the actual index used), and total_files (INT). The index/total_files pair is what a loop uses - set start_index from a loop counter and you walk the folder one file per iteration.

    One behavior worth knowing: the index clamps to the last file rather than erroring. Ask for index 99 in a 5-file folder and you get file 4, silently. That's forgiving, but it means an overrunning loop will quietly re-read the final prompt instead of stopping.

    Install

    Part of Comfyui-PixNodes. ComfyUI Manager → search "PixNodes" → install → restart, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/pixixai/Comfyui-PixNodes
    

    then restart. (The README's manual-install block references the wrong repo, ComfyUI-AlignLayout - use the URL above.)

    What to watch

    The error messages are the blunt kind: a bad path raises a red-node error ("The provided path is not a valid directory"), and an empty folder raises too - there's no graceful "no files" fallback, so validate the path before you queue a big batch. It also reads files as UTF-8, so a legacy-encoded file can throw a read error. For its lane - "give me prompt number N from this folder, in human order" - it's exactly what a batch pipeline needs, and the natural companion to List from Loop or the pack's for-loop nodes on the other side.

    CategoryPixNodes/text

    Inputs (2)

    NameTypeDefaultDescription
    directorySTRING/path/to/txt/files
    start_indexINT00–10000

    Outputs (4)

    NameTypeDescription
    contentSTRING
    file_nameSTRING
    indexINT
    total_filesINT