ComfyUI Node

is dir

Is that path a folder? Ask instead of guessing

By StableLlama·Created about a year ago·Updated 4 days ago· 48
is dir
    • is dir
    path

    Basic data handling: PathIsDir ("is dir") answers one question: does this path exist and is it a directory? Path in, BOOLEAN out. It's the sibling of PathIsFile, and together they're the answer to the most common flaw of the bare PathExists node - which happily returns True for both files and folders and leaves you to guess which.

    You'll reach for this when the distinction actually matters to your pipeline. Maybe you're scanning a directory tree and want to recurse into subfolders while skipping files (or the reverse). Maybe you're validating an output location before a save node runs - PathSaveImageRGB can create its own directories, but you might want to branch and do something different if the target is a directory rather than a file path. Whatever the case, this is the node that turns "some path exists" into "this path is a folder, do the folder thing."

    How it works

    A direct call to Python's os.path.isdir(path). The semantics matter and are easy to get wrong if you've been leaning on PathExists:

    • It returns True only if the path exists and is a directory.
    • A file returns False. A nonexistent path returns False. So False means "not a directory right now" - it doesn't tell you why.
    • Unlike PathGetSize or PathListDir, it does not throw on a missing path. It's a gentle check, which is exactly why you pair it with those stricter nodes as a guard.

    Inputs and outputs

    • path (STRING, default "") - the path to test.
    • is dir (BOOLEAN) - True only if the path exists and is a directory.

    Installing it

    Part of Basic data handling, the zero-dependency pack. Install via ComfyUI Manager (search "Basic data handling") and restart, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    Restart after. No models to download, no extra pip packages.

    Common gotchas

    The one that trips people: this is a live check, not a cached one, so it reflects disk state at execution time. If a directory gets created or deleted between your check and the node that uses the result, you're operating on stale information - same as any filesystem utility, but worth remembering if you're building long pipelines.

    The other classic mistake is using it where PathIsFile belongs. If you want "is this a usable regular file for PathLoadImageRGB," checking is dir gives you False for both "it's a file" and "it doesn't exist," which is not the same information. Use the right check for the right question. Small node, clear job, and it slots neatly into any branch that needs to know what kind of thing a path points at.

    CategoryBasic/Path

    Inputs (1)

    NameTypeDefaultDescription
    pathSTRING

    Outputs (1)

    NameTypeDescription
    is dirBOOLEAN