Nodes/ComfyUI-Apt_Preset/IO_PathProcessor
ComfyUI Node

IO_PathProcessor

Filter, sort, and clean up a list of file paths with regex

By cardenluo·Created 2 years ago·Updated 22 days ago· 309
IO_PathProcessor
    • NewPathList
    • FileNameList
    • FolderList
    path_list
    remove_file_suffixtrue
    filter_suffixes
    regex_filter
    regex_sort_pattern
    sort_orderup
    path_duplication_count1

    If you've ever had a folder of files named img12.png, img(45).png, and AI图片63.png and needed them sorted by the number buried somewhere in each name, you know that's not a job for a plain alphabetical sort. IO_PathProcessor is a batch path cleaner built for exactly that mess - filter, extract a sort key with regex, order the results, and hand back clean parallel lists.

    How it works

    Feed it path_list, a batch of file paths, and it runs them through a pipeline: filter_suffixes and regex_filter narrow down which paths survive at all, regex_sort_pattern pulls a value out of each surviving filename to sort by, and sort_order (up/down) decides the direction. The README documents the three sort-pattern shapes it's built around, and they cover the practical cases you'll actually hit:

    • Number at the start - ^(\d+) - pulls 12 out of 12AI图片.png
    • Number at the end - (\d{2})(?=\.\w+$) - pulls 63 out of AI图片63.png
    • Number in parentheses - \((\d+)\) - pulls 45 out of 图片(45).png

    remove_file_suffix (default true) strips extensions from the output filenames, and path_duplication_count lets you repeat each surviving path N times in the output - handy if downstream you need, say, three passes per source image and don't want to build that repetition by hand.

    Inputs and outputs

    The fields you'll actually touch: path_list (the input batch), regex_filter (keep only matching paths), regex_sort_pattern (extract the sort key), sort_order, and path_duplication_count. filter_suffixes and remove_file_suffix round out the extension handling.

    Three outputs, all STRING lists: NewPathList (the filtered, sorted paths), FileNameList (just the filenames), and FolderList (just the containing folders) - pick whichever shape the next node in your graph wants.

    How to install it

    ComfyUI Manager → search ComfyUI-Apt_Preset, install, restart. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/cardenluo/ComfyUI-Apt_Preset.git
    

    then run install.bat for dependencies (Windows-only - on Linux/macOS run its pip install lines by hand) and restart ComfyUI.

    Common issues & troubleshooting

    Don't hand-write regex if you don't have to. This pack ships a companion node, IO_RegexPreset, that builds a working pattern from a plain-language preset (contains keyword, starts with, matches digits, and so on) and outputs it as a STRING - pipe that straight into regex_filter or regex_sort_pattern instead of debugging your own regex against real filenames.

    A sort pattern that doesn't match anything just doesn't sort. If regex_sort_pattern doesn't find a match in a given filename, that path has no sort key to work with - test your pattern against a couple of real filenames from the batch (or use IO_RegexPreset's own preview_test_text field to check it) before trusting the output order.

    IMPORT FAILED on startup. This pack has at least one reported import failure in the wild on a stock install, generally traced to skipping the install.bat dependency step - easy to miss off Windows, where you have to run its pip install lines yourself. Check the console for the specific missing package first.

    CategoryApt_Preset/IO_Port

    Inputs (7)

    NameTypeDefaultDescription
    path_listSTRING
    remove_file_suffixBOOLEANtrue
    filter_suffixesSTRING
    regex_filterSTRING
    regex_sort_patternSTRING
    sort_orderCOMBOup2 options: up, down
    path_duplication_countINT11–100

    Outputs (3)

    NameTypeDescription
    NewPathListSTRING
    FileNameListSTRING
    FolderListSTRING