Nodes/ComfyUi-MpiNodes/Mpi Batch Text Replace
ComfyUI Node

Mpi Batch Text Replace

Find-and-replace across every prompt file in a folder, in one run

By MadPonyInteractive·Created 11 months ago·Updated 5 days ago· 3
Mpi Batch Text Replace
    • status
    • output_folder
    input_folder
    output_folder
    find_string
    replace_string

    If you manage prompts as text files - and plenty of serious prompt libraries are exactly that - you've hit the moment where a shared tag changes and you need to edit forty files. Mpi Batch Text Replace is the find-and-replace that does the whole folder at once. Point it at an input folder, give it a find_string and a replace_string, and it rewrites every .txt file inside, writing the results to an output folder without touching your originals.

    The mechanism is thoughtfully defensive about encodings, which is the part most naive batch tools get wrong. It reads each file trying UTF-8 first and falls back to cp1252 (the Windows Latin-1-ish encoding) on a UnicodeDecodeError - so old prompt files that were saved by tools with lazy encoding defaults don't crash the batch. It then normalizes the content with unicodedata.normalize("NFKD", ...) to canonicalize legacy characters before doing a plain content.replace(find_string, replace_string), and writes everything back out as UTF-8. The NFKD pass is the quiet detail that keeps your output consistent even when the input was messy.

    Inputs: input_folder, output_folder, find_string, and replace_string - four plain text fields. Outputs: status (STRING, like "Processed 12 file(s)") and output_folder (STRING, echoing the output path back so you can chain it into a loader). Two behaviors worth knowing: if the input folder doesn't exist, it raises (Input folder does not exist: ...) rather than silently doing nothing - loud, and correct, since a silent zero-file batch is how mistakes hide. If the output folder doesn't exist, it creates it. It's a non-output node, so it runs when its branch runs, not on every submit.

    Where this earns its place: prompt-library maintenance. You've got a folder of positive-prompt files that all reference a trigger word, a character name, or a style token, and the convention changed. One run of this node updates every file into a new folder, and you diff the two folders if you want to eyeball the changes before promoting them. It's also the batch half of the pack's prompt-generation workflow - a library built from generated prompts often needs a global cleanup pass exactly like this.

    The honest caveats: it only matches literal text, not regex or wildcards, and it only touches files that end in .txt (case-insensitive). The output folder is a destination, not an in-place edit - if you want to overwrite your originals, point the output folder at the same directory. And because it's a node in a graph, it runs as part of the workflow: it's file-side work, so it belongs in a maintenance workflow, not the middle of a generation pipeline. For a one-off job, honestly, the shell one-liner sed alternative exists - but if your pipeline already runs in ComfyUI, this keeps the whole operation inside the graph with zero scripting.

    Install is pack-standard: ComfyUI Manager → search ComfyUi-MpiNodes → install, or clone it:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes
    

    Restart, and it's under MpiNodes/TextOps. No requirements file, no model downloads - pure Python on top of ComfyUI, the same pack behind the Cubric Vision app.

    CategoryMpiNodes/TextOps

    Inputs (4)

    NameTypeDefaultDescription
    input_folderSTRING
    output_folderSTRING
    find_stringSTRING
    replace_stringSTRING

    Outputs (2)

    NameTypeDescription
    statusSTRING
    output_folderSTRING