Nodes/comfyui-huyl2-nodes/Clear Folder By Pattern
ComfyUI Node

Clear Folder By Pattern

A scoped version of this pack's blunt rm -r *

By huyl3-cpu·Created 9 months ago·Updated 4 months ago· 1
Clear Folder By Pattern
    • result
    folder_path
    pattern*

    This is the more careful sibling of Clear-Folder elsewhere in this pack. Instead of wiping an entire directory, it deletes only files matching a pattern you give it - clear out just your scratch PNGs, just old segment files, and leave everything else in the folder alone.

    Why you'd want this over the unscoped version

    If a working folder holds a mix of files you want cleared and files you want to keep - outputs alongside logs, or segments from more than one job sharing a directory - Clear-Folder's all-or-nothing delete is too blunt. This node lets you scope it: give it a glob-style pattern (*.png, segment_*.mp4) and only matching files get removed.

    How it works

    folder_path plus pattern - the default pattern is "*", meaning everything, so if you don't change it, this node behaves identically to the unscoped Clear-Folder. Like that node, this one is marked as an output node (is_output_node: true), which means it runs as a terminal step in the queue whenever the graph reaches it, whether or not anything downstream reads its result.

    Inputs and outputs

    • folder_path (STRING, required) - the directory to clean.
    • pattern (STRING, default "*") - the glob-style match; only files matching this get deleted.
    • Output: result (STRING) - presumably a status message.

    Installing it

    No models or extra dependencies mentioned in the README - plain filesystem code. Search ComfyUI Manager for the repo name first, but a small personal pack like this may not be indexed there:

    cd ComfyUI/custom_nodes
    git clone https://github.com/huyl3-cpu/comfyui-sortlist.git
    

    Restart ComfyUI afterward.

    Common issues and troubleshooting

    The default pattern deletes everything, same as the unscoped node. If you reached for this node specifically because you wanted the scoped behavior, don't forget to actually set pattern to something narrower than "*" - left at default, it's exactly as destructive as Clear-Folder, just with an extra input you didn't fill in.

    Same standing warning as its sibling: no confirmation, no dry run. It's still a recursive-style delete triggered automatically as an output node. Test your pattern against a throwaway copy of the folder before wiring this into anything that runs unattended, like a loop or a scheduled batch.

    The pattern syntax isn't documented in the schema. Glob-style matching (*, ?, [abc]) is the standard assumption for a "pattern" field like this in Python tooling, but there's no explicit reference for exactly what's supported. If you need precise matching, confirm the behavior against a couple of throwaway test files before trusting it against real data.

    Categorycomfyui-sortlist

    Inputs (2)

    NameTypeDefaultDescription
    folder_pathSTRING
    patternSTRING*

    Outputs (1)

    NameTypeDescription
    resultSTRING