ComfyUI Node

Sort List

Sort a list of strings — including file lists, by date or folder

By TinyBeeman·Created about a year ago·Updated about a month ago· 1
Sort List
    • sorted_list
    string_list
    sort_methoddefault
    sort_ascendingtrue
    seed0

    ComfyUI gives you lists of strings everywhere - file paths, prompts, image names - and mostly leaves the ordering to whatever produced them. Sort List is TinyBee's fix for that. On the surface it's a boring sorter; underneath it has a few file-aware modes that make it genuinely useful for batch and animation work.

    How it works

    In goes string_list (a real ComfyUI list of strings, so wire it from a list-producing node, not a plain text box), plus a sort_method dropdown with six choices:

    • default - plain string sort
    • date - sorts by file modification time (entries that aren't paths sort as if they were the oldest)
    • filename - sorts by the basename of each path, ignoring the folder
    • parent folder - sorts by the directory each path lives in
    • full path - sorts by the absolute path
    • random - seeded shuffle

    There's also a sort_ascending toggle (labeled Ascending/Descending) and a seed input that only matters for the random mode. Set seed to -1 and the shuffle is genuinely random each run; give it any other number and the same seed reproduces the same order every time - the right tool when two workflows need to agree on a "random" sequence.

    The node sorts in place and re-runs on every execution (it always reports itself as changed), so you won't get stale orders from ComfyUI's caching.

    Where you'd reach for it

    Paired with the pack's Get File List node, this is the piece that makes file-based batches behave. Load a folder of frames, sort by filename so they feed a video or image-batch pipeline in the right order instead of whatever order glob returned. Sort by date when you want the newest renders first. And the seeded random shuffle is handy for reproducible prompt or dataset sampling.

    Install

    Part of ComfyUI-TinyBee. Via ComfyUI Manager, search ComfyUI-TinyBee and install; or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TinyBeeman/ComfyUI-TinyBee
    

    Restart ComfyUI - the node shows up under 🐝TinyBee/Lists. It needs nothing but the Python standard library. The pack's pillow/jsonata requirements belong to its image and JSON nodes, not the list ones.

    Gotchas

    The file-aware modes (date, filename, parent folder, full path) assume your strings are filesystem paths, and they call os.path functions on whatever you feed them. Non-path strings won't crash the default case, but date will treat a missing file's mtime as 0 - so an entry that isn't a real path can sort to the oldest slot. Also, sort_ascending off just reverses the sorted result; it doesn't do anything clever. And remember the default sort is plain Python string ordering, so "10" sorts before "9" - if you're sorting version numbers, this is the wrong tool.

    Category🐝TinyBee/Lists

    Inputs (4)

    NameTypeDefaultDescription
    string_listSTRING
    sort_methodCOMBOdefault6 options: default, date, filename, parent folder, full path, random
    sort_ascendingBOOLEANtrue
    seedINT0-1–18446744073709550000

    Outputs (1)

    NameTypeDescription
    sorted_listSTRING