Nodes/ComfyUI-OllamaPromptsGeneratorTlant/Load Random Txt File Tlant
ComfyUI Node

Load Random Txt File Tlant

The Simplest Random Text Loader in This Pack (And the One to Skip)

By Tlant·Created 2 years ago·Updated 5 months ago· 2
Load Random Txt File Tlant
    • file_content
    directory_path

    This is the original random text loader that the Tlant pack grew up from - one input, one output, nothing else. Point it at a folder full of .txt prompt files and every execution it picks one at random and returns the contents. It's the seed of an idea that the same pack later refined into V2, V3, and the "Smart" V4 loader. For the specific niche of "serve me a random prompt from a folder," it works exactly as advertised. It's also the version you'll have the least reason to install.

    How it works

    The mechanism is about as short as a node gets: os.listdir the directory, keep files ending in .txt, random.choice one of them, read it as UTF-8, return it as file_content. Its IS_CHANGED method returns a fresh random number every call, which forces ComfyUI to re-execute it each run so you actually get a new file instead of ComfyUI's cache returning the same prompt forever.

    The one input is directory_path (a plain string, no default folder - you type it), and the one output is file_content (STRING), which wires straight into a text encoder or into one of the pack's Ollama nodes as reference text.

    Install

    Same pack as the other fifteen nodes here:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Tlant/ComfyUI-OllamaPromptsGeneratorTlant
    

    then restart ComfyUI. Or find it under "Load Random Txt File Tlant" in ComfyUI Manager's custom node search.

    The honest take

    The reason to skip V1 isn't that it's broken - it's that its own pack outgrew it. A couple of things betray its age:

    • Error strings come back as output, in Chinese. A bad path returns "指定的路径不是一个有效的目录。" ("the specified path is not a valid directory") as your file_content, not as a console error. Newer versions of these loaders switched to English and clearer behavior.
    • No seed. V2 adds a seed input so the same run is reproducible. V1 is pure luck every time.
    • No recursion, no picker. V2 gives you recursion; V3 gives you a subdirectory picker. V1 makes you type an absolute path and only scans the top level.

    So: if you've got an old workflow that already uses LoadRandomTxtFileTlant, it'll keep working and you don't need to migrate. If you're building something new, grab V3 (or V4) instead - same idea, more control, and you'll save yourself the "why is my prompt a Chinese error message" confusion.

    CategoryCustom Nodes

    Inputs (1)

    NameTypeDefaultDescription
    directory_pathSTRING

    Outputs (1)

    NameTypeDescription
    file_contentSTRING