Nodes/Comfyui_PDuse/PD_number_star
ComfyUI Node

PD_number_star

The kitchen-sink batch renamer that also resizes and converts your images

By 7BEII·Created 2 years ago·Updated 15 days ago· 53
PD_number_star
    • result_info
    folder_path
    new_name
    prefix
    delimiter_
    number_startfalse
    padding1
    format_convert不修改
    max_size1024

    This is the pack's do-everything file tool. Point it at a folder and it can rename every file to a numbered scheme, slap a prefix on the originals, convert formats (to jpg/png/txt), and resize images to a max long edge - all in one pass, with a report string coming back out. It's the node you reach for when you just downloaded 300 training images and you want them 001_name.jpg, resized to 1024, with the giant 4K originals deleted, without writing a Python loop.

    It lives in the ZHO Tools category, which tells you it was built for a specific Chinese dataset-pipeline habit: sequence-number your files so ordering survives any sort, and normalize image sizes for training buckets. Both instincts are sound.

    How it works

    Two mutually exclusive rename modes, and it will error if you mix them:

    • new_name set - every file becomes new_name + a number (or just new_name if padding is 0). With number_start = true the number goes first (001_newname.ext); otherwise it goes last (newname_001.ext).
    • prefix set - the original filename is kept and prefix + an optional number is glued on, again honoring number_start.

    The delimiter between number and name is your delimiter (default _). Then, on top of renaming: if format_convert is set, extensions change (jpg/png/txt); if it's jpg or png, the image is actually re-encoded, resized so its longest side hits max_size (LANCZOS), and the original file is deleted after. Converting to JPG flattens alpha onto white, which is usually what you want for training data.

    The inputs that matter

    • folder_path - required, must exist or you get an error string back.
    • new_name / prefix - exactly one of these; the node refuses both.
    • padding (0–9) - zero-width or padded numbers. padding = 0 means no number at all.
    • format_convert - 不修改 (don't change), jpg, png, or txt. Note txt conversion just changes the extension, it doesn't re-encode.
    • max_size (64–4096) - longest-edge limit for image re-encoding.

    The single output, result_info, is a plain-text report: success/failure counts plus a original → new_name list for every renamed file.

    Installing it

    Part of Comfyui_PDuse by 7BEII. 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. No models to download; the pack pulls numpy, Pillow, scipy, opencv-python, torchvision. Chinese-first docs (Feishu/Bilibili), so expect sparse English.

    Where people get burned

    The obvious one: this deletes the originals. When an image is re-encoded, the source file is removed - there's no "keep both" option. Work on a copy until you trust the settings. Second: it's non-recursive, only the top level of folder_path. And third, the rename numbering follows os.listdir order after skipping nothing, so the numbering isn't a stable sort unless your files were already ordered - sort your source folder by name before running if sequence order matters to you.

    CategoryZHO Tools

    Inputs (8)

    NameTypeDefaultDescription
    folder_pathSTRING
    new_nameSTRING
    prefixSTRING
    delimiterSTRING_
    number_startBOOLEANfalse
    paddingINT10–9
    format_convertCOMBO不修改4 options: NONE, jpg, png, txt
    max_sizeINT102464–4096

    Outputs (1)

    NameTypeDescription
    result_infoSTRING