Nodes/ComfyUI Sokes Nodes 🦬/Get Files in Folder with Extension 🦬
ComfyUI Node

Get Files in Folder with Extension 🦬

List every file in a folder by type, then hand it to your workflow

By m-sokes·Created 3 years ago·Updated 17 days ago· 4
Get Files in Folder with Extension 🦬
    • files_text_newlines
    • file_list
    â—„folder_pathâ–º
    â—„filename_filterâ–º
    â—„file_extensions_modeImagesâ–º
    â—„custom_extensionspng|jpg|jpeg|webpâ–º
    â—„search_subfoldersfalseâ–º
    â—„output_filesall filesâ–º
    â—„seed0â–º

    If you've ever wanted a ComfyUI workflow that discovers its own inputs instead of hardcoding them, Get Files in Folder with Extension is the node. Point it at a folder, tell it what kinds of files you care about, and it returns the matching paths - as a newline-joined string and as a proper LIST you can feed into batch processors.

    It's part of Sokes Nodes 🦬 and sits in the pack's File Paths category alongside ComfyUI Folder Paths, so it pairs naturally: pull the input or output folder from that node, then list what's inside with this one.

    How it works

    Three main controls:

    • file_extensions_mode - Images, Videos, Audio, or Custom. Preset modes cover the obvious extensions (Images spans png/jpg/jpeg/webp/gif/bmp/tiff/tga/exr/svg/heif/heic); Custom lets you type your own pipe-separated list like webm|mp4|gif.
    • filename_filter - optional wildcard filtering, with | separating multiple patterns. *image* matches anything containing "image"; photo*.png matches filenames starting with "photo" ending in .png. Leave it empty to grab everything with the matching extension.
    • search_subfolders - recurse into subdirectories or not.
    • output_files - "all files" returns everything; "single file" picks one at random, seeded by the seed input.

    The filtering is implemented with regex, and one behavior to remember: a plain word like man matches whole-word (so man.txt matches but woman.txt doesn't). Add leading/trailing * to get looser substring matching.

    Outputs: files_text_newlines (STRING - paths joined with newlines, handy for display or text nodes) and file_list (LIST - the real array for downstream processing). Both are sorted alphabetically.

    Install

    Standard Sokes Nodes 🦬 install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/m-sokes/ComfyUI-Sokes-Nodes.git
    pip install -r requirements.txt
    

    Or ComfyUI Manager → search "ComfyUI Sokes Nodes" → Install → restart.

    When you'd reach for it

    The classic use: batch workflows over a folder. Combine it with the pack's Load Random Image or a video-loading node to iterate over every file in a directory, without rebuilding the graph per file. Video people use it to pull a list of clips to process; captioning pipelines use it to enumerate a dataset.

    Gotchas: an invalid or empty folder returns empty outputs and a console error (no crash - check the terminal if you get nothing back). And "single file" mode with the same seed gives the same file, which is what you want for reproducible runs but not what you want if you expected genuine randomness - bump the seed. It's a small node with a surprisingly big payoff once you stop hardcoding file paths.

    CategorySokes 🦬/File Paths

    Inputs (7)

    NameTypeDefaultDescription
    folder_pathSTRING—
    filename_filterSTRING—
    file_extensions_modeCOMBOImages4 options: Images, Videos, Audio, Custom
    custom_extensionsSTRINGpng|jpg|jpeg|webp—
    search_subfoldersBOOLEANfalse—
    output_filesCOMBOall files2 options: all files, single file
    seedINT00–18446744073709550000—

    Outputs (2)

    NameTypeDescription
    files_text_newlinesSTRING—
    file_listLIST—