Nodes/ComfyUI_StringOps/替换文件名🐠meeeyo.com
ComfyUI Node

替换文件名🐠meeeyo.com

Rename in your graph without touching the disk — it builds the new path, you decide what to do with it

By MeeeyoAI·Created 2 years ago·Updated about a year ago· 209
替换文件名🐠meeeyo.com
  • any
  • STRING
file_pathpath/to/your/file.jpg
new_file_name

The name suggests a filesystem operation, but here's the thing that confuses everyone the first time: FileNameReplacer (替换文件名 - "replace filename") doesn't rename anything on disk. It's a pure path-builder. You give it a file path and a new name, and it returns the new path string - same folder, new name, original extension preserved. What you do with that string is up to you: feed it to a save node, a WriteToTxtFile for a manifest, or FileCopyCutNode as a destination. That makes it more flexible than a "real" rename node, as long as you understand it's just string math.

How it works

Two inputs: file_path (a full path like path/to/your/file.jpg) and new_file_name (just the name, without extension - you type hero not hero.png). The node:

  1. Splits your path into directory and extension (os.path.splitext).
  2. Sanitizes the new name - any character illegal in filenames on Windows (/, \, :, *, ?, ", <, >, |) gets replaced with _.
  3. Joins them back: dir_name/new_name + original_ext.

So path/to/your/file.jpg + heropath/to/your/hero.jpg. The original extension always survives, which is the behavior you want for batch renaming where the type shouldn't change. Output is a single STRING - the computed path. There's the usual unused optional any port, ignore it.

Why you'd reach for it

Pipeline naming. When you generate a batch and want each output saved under a computed name - same folder, new stem, .jpg intact - this builds the path you wire into a save or copy node. It also pairs with GenerateNumbers from this pack: generate 001, 002, …, concatenate with a base name, and you've got sequential filenames for a batch without touching disk until the very last step. And because it returns the path rather than acting on it, you can preview the exact path in the graph before anything executes - a nice safety property.

Install

Part of ComfyUI_StringOps:

cd ComfyUI/custom_nodes
git clone https://github.com/MeeeyoAI/ComfyUI_StringOps.git

Restart. Or ComfyUI Manager → "ComfyUI_StringOps". No models. Chinese UI (替换文件名) with the 🐠meeeyo.com branding.

Common issues

The #1 misunderstanding is expecting an actual filesystem rename - it doesn't move or modify any file, it only returns a string. The #2 gotcha: don't include the extension in new_file_name, or you'll get hero.png.png (it appends the original ext to whatever you typed). And because it sanitizes, a name like a/b silently becomes a_b - the _ tells you the original had illegal characters, but it's easy to miss. One more: it assumes a normal dir/name.ext path - a path with no directory part works (empty dir → bare filename), and a path with no extension just returns dir/new_name with no suffix added.

Think of it as a path-formatting function, not a file tool, and it'll never surprise you. If you need the actual copy/move/delete, that's FileCopyCutNode and FileDeleteNode's job.

CategoryMeeeyo/File

Inputs (3)

NameTypeDefaultDescription
file_pathSTRINGpath/to/your/file.jpg
new_file_nameSTRING
anyopt*

Outputs (1)

NameTypeDescription
STRINGSTRING