ComfyUI Node

路径验证器

Check it exists, create it if not, and count what's inside

By user2318·Created 4 months ago·Updated about a month ago· 56
路径验证器
    • exists
    • path_out
    • file_count
    path
    create_if_missingfalse
    path_prefix
    extension_filter

    Most ComfyUI errors are path errors wearing a different costume. A folder that moved, a filename typo, a directory that was supposed to be created by a previous run - they all fail somewhere downstream in a way that takes ten minutes to trace. Path Validator is the pack's pre-flight check: you give it a path, it tells you whether it exists, optionally creates missing folders for you, and counts the files inside. It turns "this will crash in the encode step" into a boolean you can gate on.

    The node auto-detects whether a path is a file or a folder - using the filesystem when the path exists, and a heuristic (trailing slash or extension) when it doesn't - then reports three outputs:

    • exists - BOOLEAN. The one you wire into a conditional/switch.
    • path_out - the resolved full path (with any path_prefix applied) when it exists, empty when it doesn't.
    • file_count - how many files are in a folder (respecting extension_filter), or -1 for files/non-directories/unreadable folders.

    What you set

    • path - file or folder path, absolute or relative.
    • path_prefix - a directory prepended to relative paths. Handy when your paths are rooted at a common folder you don't want to repeat everywhere.
    • create_if_missing - if the path is a folder and it doesn't exist, create it (default off). This is the "make sure the output dir is there before you write frames" trick.
    • extension_filter - comma-separated extensions (png,jpg) for the count; empty counts everything.

    When you'd reach for it

    • Before a save node, verifying the output folder exists (and creating it if not).
    • Before a loader, checking an input path is actually present so you can branch instead of crash.
    • Confirming a folder has the expected number of frames before a video encode - the file_count output catches "wait, only 40 frames?" before it becomes a short silent video.

    Install

    Part of user2318/ComfyUI-CustomNodeKit. ComfyUI Manager: search "CustomNodeKit". Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/user2318/ComfyUI-CustomNodeKit.git
    cd ComfyUI-CustomNodeKit
    pip install -r requirements.txt
    

    then restart. No models, no heavy deps - standard library os plus the pack base.

    The gotcha

    create_if_missing only works for directories. Point it at a missing file and it won't create anything (files need content, after all) - it just reports false. And the file/folder guess matters when the path doesn't exist yet: a path with no extension is treated as a folder, so a file you forgot to type the extension for will look like a missing directory, and file_count will be -1 rather than a helpful number. It's a validator, not a psychic - give it the path the way you'd actually use it, and it'll tell you the truth.

    CategoryCustom Nodes

    Inputs (4)

    NameTypeDefaultDescription
    pathSTRING待验证的文件或文件夹路径,支持相对路径和绝对路径。File or folder path to validate, supports relative and absolute paths.
    create_if_missingBOOLEANfalse当路径为文件夹且不存在时,是否自动创建该文件夹。Whether to automatically create the folder if it does not exist.
    path_prefixSTRING相对路径的前缀目录。若path为相对路径且此前缀不为空,将拼接为完整路径。Prefix directory for relative paths. If path is relative and prefix is not empty, they will be joined into a full path.
    extension_filterSTRING统计文件数量时的扩展名过滤。多个扩展名用英文逗号分隔,如 'png,jpg'。留空则统计所有文件。Extension filter for file counting. Separate multiple extensions with commas, e.g. 'png,jpg'. Leave empty to count all files.

    Outputs (3)

    NameTypeDescription
    existsBOOLEAN
    path_outSTRING
    file_countINT