Batch Rename Files ๐
Renumber a dataset without breaking image/caption pairs
- trigger_signal
- updated_file_count
- log
BatchRenameFiles renames every file of a given type in a folder into a clean, numbered sequence - prefix_0001.jpg, prefix_0002.jpg, and so on. The feature that makes it worth using over your OS's bulk-rename, though, is that it can rename the matching caption files at the same time, so your image/text pairs stay glued together.
It's from ComfyUI-MieNodes, MieMieeeee's utility pack, and it's aimed squarely at LoRA dataset prep.
The problem it actually solves
Here's the trap. A training dataset is pairs: photo_abc.jpg next to photo_abc.txt, where the .txt is the caption. The trainer matches them by shared filename. If you renumber your images to tidy them up - but don't renumber the captions to match - you've silently unpaired the whole set. Now image_0001.jpg has no caption, and photo_abc.txt describes an image that no longer exists under that name. Everything trains, nothing errors, and your results are quietly wrong.
The KB's dataset-prep guidance treats caption/image alignment as table stakes, and this node is the tool that keeps it intact while you tidy up.
How it works
directory- the folder to work on.file_extension(default.jpg) - which files to rename.numbering_format(default####) - how many digits the counter uses.####gives you0001,0002;###gives001. Zero-padding matters if you ever sort the folder alphabetically, so keep enough digits to cover your whole set.update_caption_as_well(boolean, default on) - the important one. Left on, it renames each image's twin.txtin lockstep, sophoto_abc.jpg+photo_abc.txtboth becomeprefix_0001.*. This is the whole reason to use the node. Only turn it off if you genuinely have no captions.prefix(optional) - text stuck on the front of every name, e.g.mychar. Leave it empty for bare numbers.
Outputs are updated_file_count (INT) and log (STRING). There's also an optional trigger_signal (*) for forcing run order relative to other file nodes - no data, just sequencing.
Installing it
Install the pack via ComfyUI Manager (search ComfyUI-MieNodes / ComfyUI_MieNodes, install, restart), or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/MieMieeeee/ComfyUI-MieNodes
then restart. No model download. The nodes show up under the sheep-emoji ๐ MieNodes menu.
Common issues
Leave update_caption_as_well on unless you mean it. Renaming images without their captions is the exact failure this node exists to prevent - turning the toggle off reintroduces it. If your captions somehow use a different base name than their images, the pairing can't be matched and you'll need to fix that first.
It renames in place with no undo. Copy the folder before a big renumber on a dataset you care about.
Order-of-operations with converting. If you're also flattening the dataset to one image format with BatchConvertImageFiles, decide the order deliberately - convert first so the extensions are uniform, then rename - and use the trigger_signal input to enforce that sequence rather than hoping ComfyUI runs them in the order you dropped them.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| directory | STRING | X://path/to/files | โ |
| file_extension | STRING | .jpg | โ |
| numbering_format | STRING | #### | โ |
| update_caption_as_well | BOOLEAN | true | โ |
| prefixopt | STRING | โ | |
| trigger_signalopt | * | โ |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| updated_file_count | INT | โ |
| log | STRING | โ |