Nodes/ComfyUI_MieNodes/Batch Rename Files ๐Ÿ‘
ComfyUI Node

Batch Rename Files ๐Ÿ‘

Renumber a dataset without breaking image/caption pairs

By MieMieeeeeยทCreated 2 years agoยทUpdated 25 days agoยท 225
Batch Rename Files ๐Ÿ‘
  • trigger_signal
  • updated_file_count
  • log
โ—„directoryX://path/to/filesโ–บ
โ—„file_extension.jpgโ–บ
โ—„numbering_format####โ–บ
โ—„update_caption_as_welltrueโ–บ
โ—„prefixโ–บ

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 you 0001, 0002; ### gives 001. 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 .txt in lockstep, so photo_abc.jpg + photo_abc.txt both become prefix_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.

Category๐Ÿ‘ MieNodes/๐Ÿ‘ Caption Tools

Inputs (6)

NameTypeDefaultDescription
directorySTRINGX://path/to/filesโ€”
file_extensionSTRING.jpgโ€”
numbering_formatSTRING####โ€”
update_caption_as_wellBOOLEANtrueโ€”
prefixoptSTRINGโ€”
trigger_signalopt*โ€”

Outputs (2)

NameTypeDescription
updated_file_countINTโ€”
logSTRINGโ€”