Nodes/Teskor's Utils/TS Rename Files In Dir
ComfyUI Node

TS Rename Files In Dir

Renumber a folder of frames safely (dry-run first, seriously)

By teskor-hub·Created 8 months ago·Updated 9 days ago· 4
TS Rename Files In Dir
    • COUNT
    directory
    output_directory
    sort_method
    start_index0
    files_load_cap0
    prefix
    digits4
    extensions
    dry_runfalse
    run_alwaysfalse

    Somewhere in every video workflow there's the moment a folder of frames needs to become shot_0001_.png, shot_0002_.png... in a clean sequence. You can do it in a terminal one-liner, but you can also do it in the graph where your frame sequences already live. TS Rename Files In Dir is that node - a careful batch renamer from the Teskor's Utils pack that takes every matching file in a directory and renumbers it. It rewrites names on disk, so treat it with respect and use the dry run first.

    How it works

    You point it at a directory; it sorts the files by your chosen method and renames them in index order to prefix_0001_.ext (that underscore before the extension is normal, that's just the format). There are two modes:

    • In-place - leave output_directory empty and files are renamed inside the target folder.
    • Copy mode - set output_directory and it writes renamed copies there, leaving the originals untouched. If in doubt, use this.

    The node is defensively written in ways that matter for a destructive operation. Renames happen in two phases (original → temp name → final name) so a new name can never collide with a not-yet-processed old name. It refuses to write outside the target directory - a prefix like ../../evil gets sanitized rather than honored. If anything fails mid-batch, it rolls everything back to the original names. And it caches its state (IS_CHANGED), so it doesn't re-rename your folder on every Queue press; flip run_always on if you want the old behavior back.

    The inputs that matter

    The required directory is the only thing you must set. The rest worth knowing:

    • dry_run - prints the planned mapping to the console and writes nothing. Use it first.
    • sort_method - 7 choices including Alphabetical, Numerical, and Datetime, each ASC/DESC. Set this before you commit, because the order you renumber in is the order your sequence plays in.
    • prefix and digits (4) - clip + 4 digits gives clip_0001_.mp4 style names.
    • extensions - comma/space-separated whitelist like png,jpg. Empty means every file in the folder.
    • start_index - here's the trap: it's not "start numbering at N". It's how many files to skip off the front of the sorted list. Numbering always starts at 1.

    Output: COUNT (INT) - how many files were renamed (or, on a dry run, would be).

    Install

    Part of Teskor's Utils. ComfyUI Manager → search Teskor's Utils → Install → Restart. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/teskor-hub/comfyui-teskors-utils
    pip install -r comfyui-teskors-utils/requirements.txt
    

    Restart, find it under TS Utils/Files. Dependencies are just numpy and opencv-python - this node is pure filesystem work, no models, no GPU.

    Gotchas

    The obvious one: it's destructive, so dry_run is not optional on the first pass. Read the console output, confirm the order, then run for real. Second: start_index skipping files off the front trips everyone up - if your folder starts at frame 0001 and you only want the back half renumbered, you're slicing the list, not offsetting numbers. Third, remember it's on-disk renaming, not in-memory - there's no Undo in ComfyUI, so the rollback protection only covers failures mid-batch, not "I didn't mean to do that." Copy mode (with an output directory) is the safe seatbelt.

    CategoryTS Utils/Files

    Inputs (10)

    NameTypeDefaultDescription
    directorySTRING
    output_directoryoptSTRING
    sort_methodoptCOMBO7 options: None, Alphabetical (ASC), Alphabetical (DESC), Numerical (ASC), Numerical (DESC), Datetime (ASC), +1
    start_indexoptINT00–18446744073709550000
    files_load_capoptINT0
    prefixoptSTRING
    digitsoptINT41–16
    extensionsoptSTRING
    dry_runoptBOOLEANfalse
    run_alwaysoptBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    COUNTINT