Zoey - 多文件批量重命名
Regex-friendly batch renames from inside ComfyUI — no, really, you can
- output_directory
MultiFileBatchRenamer is a file-management node pretending to be a workflow node: point it at a directory and it renames everything in it to a clean prefix + number scheme, in natural order. It's the tool for the moment when your training folder is frame (final) v2 (3).png, frame final real (1).png, and you want img0001.png, img0002.png - because your next tool (dataset prep, video frame extraction, an upscaler that insists on sequential names) demands sane filenames.
It's one of the handful of utility nodes in comfyui-ZoeyTool (Zoey Tool/文件工具), alongside the batch savers and the folder cropper. The pack leans toward Windows-path defaults and file-folder workflows, and this node is squarely in that spirit: sometimes the "workflow" you're fixing is the filesystem itself.
How it works
Set input_directory and it collects files matching file_extension (default .* - everything). Files are sorted with a natural sort key, so 2.mp4 genuinely comes before 10.mp4, which matters more than you'd think when you're renumbering a frame sequence. Then each file gets renamed.
Here's the part to read twice, because the name misleads: the node doesn't replace your filenames with just img0001. The rename actually builds prefix + number (+ _suffix) + original-name - so img0001_originalname.png. The "clean numbering" is a prefix that rides in front of the existing name. That's a deliberate, defensible choice (you never lose track of what a file was), but if you were expecting full replacement, the output will surprise you.
Two more levers before you run it:
find_text/replace_text- a simple find-and-replace pass applied to each base name first. So you can strip the(final) v2cruft from filenames and only then apply numbering. It's string replacement, not a regex engine, despite the display framing - plain substrings only.start_numberandnumber_digitscontrol where numbering starts (0is allowed) and how wide it is.
The trigger input is the subtle bit: it's a single-option input you connect a previous node's output to when you want the rename to fire as part of an ordered graph run. Leave it unconnected and the rename happens when the node executes on its own.
The lone output, output_directory, just echoes the folder path back so you can inspect or log it.
Installing it
Part of comfyui-ZoeyTool, so once again:
cd ComfyUI/custom_nodes
git clone https://github.com/liangzoey/comfyui-ZoeyTool.git
cd comfyui-ZoeyTool
pip install -r requirements.txt
Restart ComfyUI, or search comfyui-ZoeyTool in ComfyUI Manager. Pure os.rename under the hood - no models, no downloads.
Where people get burned
This node renames files in place. There is no undo. If a rename throws (say, a name collision), the file is skipped and printed to the console, but the rest of the folder keeps going - so a half-done rename leaves your directory in a mixed state. The author's own code guards against overwriting by appending the original name, but that's your safety net, not a real backup. Copy the folder first, or run it on a throwaway copy until the pattern does what you expect. And remember the find/replace is substring-based: find_text: v2 will happily hit v2 in the middle of video2k too. Check your naming pattern on one file before you let it loose on the whole directory.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| input_directory | STRING | — | |
| file_extension | COMBO | .* | 4 options: .jpg, .png, .mp4, .* |
| prefix | STRING | img | — |
| start_number | INT | 1 | — |
| number_digits | INT | 41–10 | — |
| suffix | STRING | — | |
| find_text | STRING | — | |
| replace_text | STRING | — | |
| triggeropt | COMBO | 1 options: any |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| output_directory | STRING | — |