Nodes/Comfyui_PDuse/PD_rename_V2
ComfyUI Node

PD_rename_V2

Stripping a keyword out of every image filename — in place or into a new folder

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD_rename_V2
    • result_message
    • renamed_count
    folder_path
    keyword_to_remove
    output_path

    A tagger left _R on every image filename, or your downloads all have _copy glued in, and you want them gone across a whole folder. That's this node: give it a folder and a keyword, and it removes that substring from every matching image filename - either in place, or by copying the cleaned files into a new folder while keeping the originals. Two inputs, two outputs, no surprises.

    It's the "remove keyword" sibling of PD_Name_ReplaceWordOrder in the same pack (which moves a keyword instead of deleting it) and PD_number_star (which numbers). Together they cover most of the "my filenames are a mess" cases.

    How it works

    It scans the folder (non-recursive) for image files - jpg, jpeg, png, bmp, tiff, webp - whose name contains keyword_to_remove, and builds the new name by removing that substring. A few guardrails from the source:

    • If the result would be an empty stem or just an extension, the file is skipped.
    • If the destination filename already exists, the file is skipped, not overwritten.
    • With output_path empty, it renames the originals in place. With output_path set, it copies the cleaned files to that folder (creating it if needed) and leaves the originals untouched - which is the safe mode and the reason the V2 in the name exists.
    • A file whose name doesn't contain the keyword is ignored entirely.

    The result comes back as two outputs: result_message (a readable per-file report) and renamed_count (an INT, handy for wiring into a status check or a count-display node).

    The inputs that matter

    • folder_path - required; validated, with errors returned as the result message.
    • keyword_to_remove - the substring to strip. Empty input is rejected.
    • output_path - optional. Empty = rename in place; set = copy into this folder.

    Installing it

    Part of Comfyui_PDuse by 7BEII. ComfyUI Manager (search "PDuse") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/7BEII/Comfyui_PDuse.git
    cd Comfyui_PDuse
    pip install -r requirements.txt
    

    Restart. No model downloads; pack deps are numpy, Pillow, scipy, opencv-python, torchvision. Docs are Chinese-first.

    Where people get burned

    The keyword is a plain substring, not a word-boundary match - removing R will hit R anywhere in the name, including inside Rear.jpg or car_R2.png. The pack's other renamer uses \b boundaries, so if you need word-safe deletion that's the one. Second, it only touches the image extensions listed; .txt captions in the same folder are left alone. Third, in-place mode has no undo - when you care about the originals, always set output_path. The renamed-count output also only counts files actually moved; skipped collisions land in the message, not the count.

    CategoryPD_Tools/file_operations

    Inputs (3)

    NameTypeDefaultDescription
    folder_pathSTRING
    keyword_to_removeSTRING
    output_pathSTRING

    Outputs (2)

    NameTypeDescription
    result_messageSTRING
    renamed_countINT