Nodes/honda-nodes/πŸ“‚ Rename File
ComfyUI Node

πŸ“‚ Rename File

Fix the name after the fact, inside the same run

By AvarayΒ·Created 14 days agoΒ·Updated 12 days agoΒ· 0
πŸ“‚ Rename File
    • New File Path
    β—„file_pathβ–Ί
    β—„new_nameβ–Ί

    ComfyUI names files with a counter and no punctuation, so HondaImage_00007.png tells you nothing about what's in it. You could name things properly at save time - and with the pack's Save Image you can - but sometimes the name has to be decided after the pixels exist: a seed you only learn at the end, a file you're processing rather than generating, a folder you inherited. Rename File is the cheap post-hoc fix.

    How it works

    Take the directory part of the path you give it, join your new name onto it, os.rename. That's the whole implementation. The file stays in its folder - you can't move it with this node, that's Move File's job - and New Name must include the extension, because Rename File has no idea what kind of file it's looking at. Drop the .png and you get an extension-less file that nothing will open by double-click.

    Two failure modes worth internalising before you use it in a batch.

    Missing file means silence. The body is guarded by if file_path and new_name and os.path.exists(file_path), so a path that doesn't exist does nothing at all - no exception - and the New File Path output comes back as an empty string. That empty string is your only signal. Wire it into Print to Console while you're building the pipeline and you'll see the rename didn't happen instead of discovering it three steps later.

    Target exists. It uses os.rename, so platforms disagree: on Linux and macOS an existing destination is replaced, on Windows it raises. If your new names can collide - same seed twice, same prompt - generate unique names rather than depending on overwrite behaviour.

    The inputs and outputs that matter

    File Path - absolute, tooltip says so. Normally wired from Save Image's PNG Path, Move File's output, or Load Image's Path. New Name - the new filename with extension, and it's a plain string widget you can convert to an input.

    That second socket is where the node becomes useful instead of tedious. Wire a Text Concatenate into New Name and the name is built from data: a model name, a sampler, a seed pulled out of a widget, the current run label. Set its separator to whatever reads well and its whitespace replacement to _ (which is already the default) and you get sdxl_dpmpp_2m_00007.png instead of a counter.

    One output, New File Path - the full path after the rename, or empty if it didn't happen. Feed it to a second Rename File (stages, though at that point just build the final name), to Move File to file it away, or to Print to Console to confirm.

    Because it renames in place, the practical shape is:

    Save Image PNG Path β†’ Rename File (name built by Text Concatenate) β†’ Move File (into output/sorted/<model>/)

    Order matters: rename first, then move, so the destination path you build doesn't have to guess what the file will be called.

    How to install it

    Part of Avaray/honda-nodes - ComfyUI Manager β†’ Node Pack β†’ search Honda Nodes β†’ Install β†’ restart. Manual:

    cd ComfyUI/custom_nodes
    git clone --depth 1 https://github.com/Avaray/honda-nodes.git
    cd honda-nodes
    python install.py
    

    Stdlib only; nothing in the installer is needed for this node, but it's what fetches jq and ime for the rest of the pack. No pip packages, no models.

    Common issues

    The output is empty and nothing was renamed. The source path didn't exist. Usual causes: a trailing newline or space on a wired path (clean it with Path Normalize first), a Save Image branch that didn't run, or a relative path resolving somewhere unexpected. Print the path before the rename to see the difference.

    The file lost its extension. New Name has to include it, e.g. .png. There's no auto-detection.

    Illegal characters on Windows. : * ? " < > | aren't valid in filenames there, and if you're building names from a prompt, prompts contain all of them. Strip them with Text Replace (use_regex on, find something like [<>:"/\\|?*], replace with _) before the name reaches this node.

    It renamed first then something else overwrote it. If two images in a batch resolve to the same new name, the second rename hits the collision case above. Make the name unique - append the counter you got from Save Image, or the seed.

    The rename "worked" but the image in the viewer is stale. ComfyUI's built-in preview thumbnails cache by filename; a renamed file has no preview until it's regenerated. Nothing is broken.

    Category⚑️ Honda Nodes/πŸ“‚ File System

    Inputs (2)

    NameTypeDefaultDescription
    file_pathSTRINGAbsolute path to the file.
    new_nameSTRINGNew file name (with extension).

    Outputs (1)

    NameTypeDescription
    New File PathSTRINGβ€”