Nodes/Comfyui_PDuse/PD Image List Sort (With Metadata)
ComfyUI Node

PD Image List Sort (With Metadata)

PD Image List Sort (With Metadata) — the sorter that actually uses your filenames

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD Image List Sort (With Metadata)
  • images
  • sorted_images
sort_method
reverse_orderfalse
filenames

This is the version of PD Image List Sort that does what the plain one can't: it sorts an image batch by actual filenames. ComfyUI image tensors carry no names, so this node accepts an optional filenames string (one name per line, in the batch's current order) and sorts the frames against those names using a real natsort-style key. Leave filenames empty and it degrades to the plain node's behavior - index-derived names - but the whole point is to feed it real names.

The killer use case is training-data and batch-prep work: your loader produced a batch, but you need the frames re-ordered to match a caption list, a JSON manifest, or a training script's expected sequence. This node is the alignment tool - reorder the batch to match your names, and everything downstream finally lines up.

How it works

It parses filenames by splitting on newlines (commas on a line also split), then builds a sort key per frame from its name:

  • number - extracts the first integer; zero-padding-aware so 001 sorts before 1, and 1 before 2. This is the mode for 10_R.png, 11_R.png style names where plain string sort would put 10 before 2.
  • alphabet - sorts by the first alphabetic run.
  • natural - the natsort key: digits compare numerically, text lowercases, so img2 < img10 and mixed names behave like a human would order them.

If a frame has no name supplied, it falls back to an index-derived placeholder rather than erroring. reverse_order flips the final order.

The inputs that matter

  • images (IMAGE) - the batch.
  • sort_method - number / alphabet / natural.
  • reverse_order (BOOLEAN, default off).
  • filenames (STRING, multiline, optional) - one name per line, in the batch's current order.

One output: sorted_images (IMAGE).

The one thing to get right

The filenames list must be in the same order as the batch as it arrives. That's the contract: "here's the name of frame 0, frame 1, …" and the node reorders frames to match a sorted version of those names. If your names are out of order relative to the frames, the sort will confidently reorder them according to your mismatched list. So verify the pairing before you trust the output - sort one frame's worth, spot-check, then run the batch.

Also remember the padding behavior: for number sorting, names with zero-padding sort first within the same numeric value, which is usually what you want for 01_R-style datasets. If you ever find 01 sorting oddly against 1, that's this feature, not a bug.

Install

ComfyUI Manager: search PDuse (repo 7BEII/Comfyui_PDuse), install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse
cd Comfyui_PDuse
pip install -r requirements.txt

Restart and it appears as PD Image List Sort (With Metadata) under PDuse/Image. Feed it names, get a batch in the order you actually wanted - the one sorter in this pack worth building a pipeline around.

CategoryPDuse/Image

Inputs (4)

NameTypeDefaultDescription
imagesIMAGE
sort_methodCOMBO3 options: number, alphabet, natural
reverse_orderBOOLEANfalse
filenamesoptSTRING

Outputs (1)

NameTypeDescription
sorted_imagesIMAGE