Nodes/ComfyUI-MakkiTools/get_folder_info(mki-获取文件夹文件信息)
ComfyUI Node

get_folder_info(mki-获取文件夹文件信息)

List, sort, and filter files from inside the graph

By MakkiShizu·Created about a year ago·Updated 7 months ago· 9
get_folder_info(mki-获取文件夹文件信息)
    • output_string
    • output_list
    • nth_item
    • tree_structure
    • file_count
    • has_files
    • error_message
    folder_path
    file_index1
    output_full_pathfalse
    include_subfoldersfalse
    file_filter*
    file_typesall
    sort_byname
    sort_orderascending
    limit0
    regex_filter

    ComfyUI is great at reading files it knows about - checkpoints, LoRAs, images in its model folders - and useless at reading arbitrary folders. get_folder_info_makki (display name "get_folder_info(mki-获取文件夹文件信息)") is the exception: you give it any folder path and it scans it, filters it, sorts it, and hands you back a filename, a count, or a tree view - all as graph data you can wire into other nodes.

    The realistic use case: batch processing. You point it at a folder of input images, it tells you the Nth filename, and you feed that into a loader. Or you use file_count as the loop bound for processing a folder you didn't generate in ComfyUI.

    The inputs

    There are a bunch, and they're all straightforward:

    • folder_path - the folder to scan (e.g. C:/Users/MyUser/Documents or /home/user/documents). Required.
    • file_index - which file to return in the nth_item output (1-based, sorted by your chosen order).
    • output_full_path - false returns filenames, true returns full paths.
    • include_subfolders - recurse into subfolders.
    • file_filter - glob, e.g. *.txt or image*.png.
    • file_types - all, image, text, audio, or video (extension-based).
    • sort_by - name, date_modified, or size.
    • sort_order - ascending / descending.
    • limit - cap the returned list (0 = no limit).
    • regex_filter - a regex like ^image.*\.png$ for when a glob isn't enough.

    The outputs

    Seven, which is a lot for a utility node, but each is a different way to look at the same scan:

    • output_string - all files joined into one string, one per line.
    • output_list - the same files as a proper LIST you can feed into list-consuming nodes.
    • nth_item - the single file at file_index.
    • tree_structure - a formatted ASCII tree of the folder (this is the nice one with include_subfolders - it renders subfolders as nested branches).
    • file_count - how many files matched.
    • has_files - a boolean, handy for conditional logic.
    • error_message - non-empty when the path doesn't exist or isn't a folder.

    Gotchas

    • file_index is 1-based, and out of range returns the string "Index out of range." - which will then flow into whatever you wired nth_item to, so check it if you're feeding loaders.
    • Filtering is strict about extensions when you use file_types. An uppercase .PNG may not match the lowercase extension list - set file_types to all if you're seeing mysteriously empty scans.
    • A bad path doesn't crash - it returns empty outputs plus a readable error_message. That's the node being polite; wire error_message somewhere visible if you're scripting.

    Installing

    It's in ComfyUI-MakkiTools:

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

    Restart ComfyUI. Nothing heavy in here - it's plain os walking under the hood. For anything that needs a filename from an arbitrary folder inside your graph, this is the node.

    CategoryMakkiTools

    Inputs (10)

    NameTypeDefaultDescription
    folder_pathSTRING要扫描的文件夹路径,例如 'C:/Users/MyUser/Documents' 或 '/home/user/documents' The folder path to scan, e.g. 'C:/Users/MyUser/Documents' or '/home/user/documents'
    file_indexINT11–1000要获取的第几个文件名(按名称排序),从1开始计数 The index of the file to get (sorted by name), counting from 1
    output_full_pathBOOLEANfalse如果为True,输出完整路径;否则只输出文件名 If True, output full path; otherwise output only filename
    include_subfoldersBOOLEANfalse是否包含子文件夹中的文件 Whether to include files in subfolders
    file_filterSTRING*文件筛选器,例如 '*.txt' 或 'image*.png' File filter, e.g. '*.txt' or 'image*.png'
    file_typesCOMBOall文件类型筛选 File type filter
    sort_byCOMBOname排序方式 Sort method
    sort_orderCOMBOascending排序顺序 Sort order
    limitINT0限制返回的文件数量,0表示无限制 Limit the number of files returned, 0 means no limit
    regex_filterSTRING正则表达式筛选,例如 '^image.*\.png$' Regular expression filter, e.g. '^image.*\.png$'

    Outputs (7)

    NameTypeDescription
    output_stringSTRING
    output_listLIST
    nth_itemSTRING
    tree_structureSTRING
    file_countINT
    has_filesBOOLEAN
    error_messageSTRING