Nodes/comfyui-sg-nodes/Select File From Directory
ComfyUI Node

Select File From Directory

A File Picker for Any Folder on Your Machine

By sebagallo·Created 9 months ago·Updated 6 months ago· 0
Select File From Directory
    • FULL_PATH
    • RELATIVE_PATH
    • FILE_NAME
    folder_path
    extensions
    filter_type
    filter_text
    file_name

    ComfyUI's built-in loaders only see its own folders. Select File From Directory breaks that wall: it lists files from any folder on your machine, recursively, filters them however you like, and hands you back the paths. If you've ever had to copy a batch of images into ComfyUI/input just so a loader would see them, this is the node that makes that chore obsolete.

    It's built around a live, dynamic dropdown. You type an absolute folder_path, optionally narrow with extensions and a filter, and the file_name dropdown fills itself in with everything that matches. The mechanism is a small client-server dance: a frontend script watches the folder/extension/filter widgets, and on any change it asks ComfyUI's server (a /sg-nodes/list_files endpoint) to re-scan the directory. The server walks the folder and all subdirectories, applies your filters, and sends back a sorted list that the dropdown swaps in instantly. Change a filter, and the list updates without touching anything else.

    The inputs that matter

    • folder_path - absolute path to scan. This one has to be real: the server checks os.path.isdir and returns an empty list for anything that doesn't exist or isn't a directory.
    • extensions - comma-separated, e.g. .png, .jpg. Leading dots are optional (it adds them for you). Empty means everything.
    • filter_type - none, contains, or regex, applied on top of the extension filter. contains does a case-insensitive substring match against the relative path; regex does a case-insensitive regex search.
    • file_name - the populated dropdown.

    Three outputs: FULL_PATH (absolute), RELATIVE_PATH (relative to the folder, subfolders included), and FILE_NAME (just the base name). Hand any of them to nodes that accept path strings.

    Where it earns its keep

    Batch pipelines are the obvious use: point it at a directory of video frames or dataset images, wire FULL_PATH into a loader that takes path strings, and the whole batch flows without moving files around. The RELATIVE_PATH output is a nice touch for things like metadata or caption files that need to match the folder structure.

    Two gotchas from the source. First, the node only emits real output when both folder_path and file_name are set - otherwise it returns empty strings, silently. Second, the recursive scan has no exclusions, so pointing it at a huge directory (or a folder full of node_modules) makes the dropdown refresh slow. Keep it pointed at folders you actually want to list. And remember the paths are served relative to the folder you typed, so if you move the folder after selecting a file, the stored selection goes stale.

    Install

    Part of comfyui-sg-nodes by sebagallo. ComfyUI Manager → search comfyui-sg-nodes, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/sebagallo/comfyui-sg-nodes
    

    Restart ComfyUI; it's under SGNodes/Utilities. No model downloads, no extra dependencies.

    CategorySGNodes/Utilities

    Inputs (5)

    NameTypeDefaultDescription
    folder_pathSTRINGThe absolute path to the directory to scan.
    extensionsSTRINGComma-separated list of allowed extensions (default: empty searches all).
    filter_typeCOMBOType of additional filtering (none, contains, regex).
    filter_textSTRINGThe text or regex pattern for the selected filter type.
    file_nameCOMBOThe selected file from the dynamic dropdown list.

    Outputs (3)

    NameTypeDescription
    FULL_PATHSTRING
    RELATIVE_PATHSTRING
    FILE_NAMESTRING