ComfyUI Node

Load Random Text File V3

The Random Prompt Loader That Finally Got a Directory Picker

By Tlant·Created 2 years ago·Updated 4 months ago· 2
Load Random Text File V3
    • text
    • txt_file
    • seed
    dir_path
    seed1
    is_recursivefalse
    sub_dir_list
    selected_sub_dir

    This pack ships three random text loaders and a fourth "smart" one, and V3 is the one most people end up on. The idea is dead simple: you keep a folder full of .txt prompt files, this node grabs one at random each run, and its text output feeds your text encoder. One run gets you "a cyberpunk street market at dusk," the next gets you "a lighthouse in a storm." Prompt roulette for people too lazy to write a hundred prompts in the UI.

    How it works

    V3 collects every .txt file under dir_path (recursively if is_recursive is set to "true"), then uses your seed to pick one via random.seed(seed). Same seed, same directory, same file every time - which is the whole point of the seed input. It reads the file with a utf-8gbklatin-1 fallback chain, so even prompt files saved with non-UTF-8 encodings usually come through.

    What actually makes it V3 rather than a copy of V2 is the subdirectory machinery. There are two extra inputs - sub_dir_list and selected_sub_dir - backed by a custom server route (/get_subdirectories) and a JavaScript extension that ships with the pack. Together they give you a folder-picking button on the node, so you can browse to a subfolder instead of hand-typing nested paths. That's the killer feature: the other loaders in the family make you type absolute paths, and V3 is the one that doesn't.

    Inputs and outputs that matter

    • dir_path - the folder to scan. Needs to be a real absolute path; an empty string will just error out.
    • seed - the reproducibility knob. Bump it to force a different file.
    • is_recursive - "false" (default) only scans the top level; "true" walks every subdirectory.
    • sub_dir_list / selected_sub_dir - populated by the picker UI; usually you don't touch these by hand.

    Outputs: text (the file's contents), txt_file (absolute path of the chosen file, handy if you want to log or branch on it), and seed (echoes your seed back so you can pass it downstream).

    Install

    Same story as the rest of the pack - ComfyUI Manager, search "Load Random Text File V3" or just the pack name, or:

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

    Restart ComfyUI and you're done. No models to download, no heavy dependencies.

    Where people get tripped up

    The sneaky one: when the path is wrong or no .txt files exist, the node doesn't raise an error in the console - it returns the error message as the text output. So your prompt text widget suddenly contains "Directory not exists: ..." and that's what gets encoded. Check the text output before you blame the sampler.

    On Windows, either escape backslashes in the path (G:\\prompts) or just use forward slashes - Python handles both. And if you're torn between V1, V2, V3 and the "Smart" V4: V3 is the one with the picker, which is the difference you'll actually feel in daily use.

    CategoryCustom Nodes/File Operations

    Inputs (5)

    NameTypeDefaultDescription
    dir_pathSTRING
    seedINT10–18446744073709550000
    is_recursiveCOMBOfalse2 options: true, false
    sub_dir_listSTRING
    selected_sub_dirSTRING

    Outputs (3)

    NameTypeDescription
    textSTRING
    txt_fileSTRING
    seedINT