Nodes/Comfyui_PDuse/PD:number_start
ComfyUI Node

PD:number_start

Fixing 'T_1, T_2, T_10' filename sorting in one click

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD:number_start
    • result_info
    folder_path
    target_prefixT

    You know the file listing that never sorts right: T_1.jpg, T_2.jpg, T_10.jpg, where T_10 insists on sitting between T_1 and T_2 because file managers sort strings, not numbers. This node fixes the convention at the source - it renames T_11_T, T_22_T, T_1010_T, so numerical order and alphabetical order finally agree. The "T" is a placeholder; you set the prefix to whatever your files actually use.

    It's a one-trick node and happy about it. Two inputs, one report string out. If your workflow is "rename training data so batches process in the right order," this is the right-sized tool.

    How it works

    Give it a folder_path and a target_prefix (default T). It builds a regex of the form ^PREFIX_(\d+)(\..+)?$ and matches every file in the folder against it. Matches get sorted numerically - so T_2 sorts before T_10 - and renamed to number_PREFIX.ext. Files that don't match the pattern are left alone and reported as skipped. A few details from the source worth knowing:

    • It works on any extension, since the extension is just carried along in the match.
    • If the destination name already exists, the rename is skipped and reported, never overwritten.
    • The prefix match is exact and must be followed by _ + digits; TT_1 won't match with prefix T.

    The output, result_info, is a tidy report: matched count, renamed count, failures, skipped files, and a old → new list for each rename.

    The inputs that matter

    • folder_path - the folder to operate on. Errors out as a string if it doesn't exist.
    • target_prefix - the token before the number. Set it to your actual prefix (e.g. T, IMG, 10_R if that's your naming). Empty is rejected.

    That's genuinely it.

    Installing it

    It ships in Comfyui_PDuse by 7BEII, alongside the pack's other file tools. ComfyUI Manager (search "PDuse") or:

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

    Restart ComfyUI. No models, no API - dependencies are the pack's standard numpy, Pillow, scipy, opencv-python, torchvision. Docs are Chinese-first (Feishu wiki, Bilibili).

    Where people get burned

    The regex is strict: T_1 matches, T1 and T-1 don't. If your files use a different separator, this node won't touch them (rename them first or pick the delimiter-carrying pack sibling). And as always with this pack's renamers: it rewrites real files in place with no undo, so back up before pointing it at anything you can't re-download. The whole "T" scheme is also a sign you're doing one-way dataset prep - once it's renamed, there's no going back.

    CategoryZHO Tools

    Inputs (2)

    NameTypeDefaultDescription
    folder_pathSTRING
    target_prefixSTRINGT

    Outputs (1)

    NameTypeDescription
    result_infoSTRING