ComfyUI Node

list dir

List everything in a folder — files only, dirs only, or both

By StableLlama·Created about a year ago·Updated 4 days ago· 48
list dir
    • entries
    path
    files_onlyfalse
    dirs_onlyfalse

    Basic data handling: PathListDir ("list dir") reads a directory and hands you its contents as a list of names - every entry by default, or filtered to files only or directories only. It's the node you reach for when you need to process a folder you can't describe with a PathGlob pattern, or when you want to see everything in it, junk included.

    The glob vs. list dir split is the mental model that helps: PathGlob answers "what matches this pattern?" while PathListDir answers "what's actually in here, no pattern required?" If you want every PNG, glob is cleaner. If you want to iterate a folder and decide per-entry what to do - load the images, skip the subfolders, flag anything unexpected - list dir gives you the raw material and this pack's list nodes do the deciding.

    How it works

    It calls Python's os.listdir(path) and then applies the filters. Three things to know:

    • The output is entry names, not full paths. os.listdir returns bare names like photo.png, not C:\input\photo.png. To load them, join each name onto the directory with PathJoin first. This is the gotcha that catches everyone on the first try - the list looks right until you feed a bare name to a loader that wants a full path.
    • It raises on bad input. If the path doesn't exist, it throws FileNotFoundError; if the path is a file rather than a directory, NotADirectoryError. Gate it behind PathIsDir if your input might be unreliable.
    • Filters are files_only and dirs_only, both BOOLEAN (default off). Both off → everything. The source applies files_only first; if you set both, files_only wins and you get files.

    Inputs and outputs

    • path (STRING, default "") - the directory to list. Empty defaults to the current working directory (check PathGetCwd if that surprises you).
    • files_only (BOOLEAN, default off) - only files.
    • dirs_only (BOOLEAN, default off) - only directories.
    • entries (STRING list) - the matching names, unsorted in the raw os.listdir sense (order is whatever the OS returns).

    Installing it

    Ships in Basic data handling, zero dependencies. ComfyUI Manager → search "Basic data handling" → install → restart. Manual:

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

    Restart after. No models, no pip.

    Where it bites

    The bare-names thing is the big one - every "why can't this load my file" with this node traces back to forgetting the PathJoin. The raising-on-missing-dir behavior is the second: in an automation loop, a folder that stops existing mid-run kills the whole graph. Guard with PathIsDir and you're fine. And note there's no sorting guarantee, so if order matters, run the result through the pack's list-sort node. Solid utility, one mental adjustment, and then it's a workhorse.

    CategoryBasic/Path

    Inputs (3)

    NameTypeDefaultDescription
    pathSTRING
    files_onlyoptBOOLEANfalse
    dirs_onlyoptBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    entriesSTRING