2026-01-25 12:31:20 +08:00
2026-01-25 05:21:19 +08:00
2026-01-25 03:18:27 +08:00
2026-01-25 12:31:20 +08:00
2026-01-25 04:11:12 +08:00
2026-01-25 05:21:19 +08:00

ComfyUI-FilePathsFromFolder

A simple ComfyUI custom node pack for loading and selecting files from folders, with for-loop support for batch processing.

Nodes

LoadFilePathsFromFolder

Scans a folder for files matching a specific extension pattern.

Parameters:

  • folder_path: Path to the folder to scan
  • extension: File extension pattern (e.g., ".png", ".jpg", "*.txt")

Outputs:

  • filepaths: Line-break separated list of full file paths
  • filenames: Line-break separated list of filenames without extensions
  • count: Number of files matched

GetPathByIndex

Selects a specific file from the lists by index.

Inputs:

  • filenames: Line-break separated filenames (from LoadFilePathsFromFolder)
  • filepaths: Line-break separated filepaths (from LoadFilePathsFromFolder)

Parameters:

  • index: Index of the file to select (0-based)

Outputs:

  • filename: Selected filename
  • filepath: Selected filepath

Loop Nodes

FilePathsForLoop

Initiates iteration through files in a folder. Uses ComfyUI's list-based batching to process each file individually.

Parameters:

  • folder_path: Path to the folder to scan
  • extension: File extension pattern (e.g., ".png", ".jpg", "*.txt")

Outputs:

  • filepath: Full path of current file (list output - each item processed separately)
  • filename: Filename without extension (list output)
  • current_index: Current iteration index, 0-based (list output)
  • total_count: Total number of files (list output)

Important: This node outputs lists with OUTPUT_IS_LIST = True. ComfyUI will automatically run all connected nodes once for each item in the list. Each connected node receives a single value from the list per execution, not the entire list.

FilePathsLoopClose

Closes the file paths loop and collects iteration results.

Inputs:

  • current_index: Current index from FilePathsForLoop (required, force input)
  • iteration_data: Optional output from FilePathsEnsureExecution or any node in the loop

Outputs:

  • total_iterations: Total number of iterations completed

Usage: This is the termination point of your loop. Connect the current_index from FilePathsForLoop (or through other nodes) to ensure the loop completes. If you need to ensure multiple nodes execute, connect them to FilePathsEnsureExecution first, then connect FilePathsEnsureExecution's output to this node's iteration_data input.

FilePathsEnsureExecution

Ensures connected nodes execute during loop iteration by collecting their outputs.

Inputs:

  • input_1 through input_5: Optional inputs (supports any type with wildcard *)

Outputs:

  • passthrough: The first non-None input value

Usage: Connect outputs from any nodes that need to execute within the loop to this node's inputs. Then connect this node's output downstream (e.g., to FilePathsLoopClose) to ensure all connected nodes complete execution. If you need more than 5 inputs, chain multiple FilePathsEnsureExecution nodes together - connect the first node's output to one of the second node's inputs.

How ComfyUI List-Based Loops Work

When a node has OUTPUT_IS_LIST = True:

  1. The node returns lists: ["file1.png", "file2.png", "file3.png"]
  2. ComfyUI automatically executes all downstream nodes once per list item
  3. Each execution receives one item from the list, not the whole list
  4. Iteration 1: downstream nodes receive "file1.png"
  5. Iteration 2: downstream nodes receive "file2.png"
  6. Iteration 3: downstream nodes receive "file3.png"

This is ComfyUI's native batching/looping mechanism.

⚠️ Memory Management Warning

Important: The simple loop mechanism in this node pack iterates by node execution, not by iteration cycle. This means all nodes in the loop execute for each file, which can lead to Out of Memory (OOM) errors if proper memory management is not implemented, especially when processing large batches or using memory-intensive operations.

Recommendations:

  1. For Node-Based Loops (using FilePathsForLoop):

    • Use clean VRAM or clean RAM nodes after heavy procedure nodes complete (e.g., after any model loading required nodes like image generation, audio generation, or video generation)
    • This ensures proper cleaning and unloading of unneeded models between iterations
    • Example: After your image generation node, connect a "Clean VRAM" or "Clean RAM" node before the next iteration
  2. For Sequential Loops (true iteration cycles):

    • Recommended: Use third-party for-loop/while-loop custom nodes for sequential iteration
    • Use LoadFilePathsFromFolder node to get file count (as loop count) and file names data
    • Pass the file count to your third-party loop node to set the iteration count
    • Within the loop, connect the current index value to GetPathByIndex node
    • Connect filenames/filepaths from LoadFilePathsFromFolder to GetPathByIndex node's inputs
    • This approach provides better control over memory management and true sequential processing

Example Workflows

Simple Loop Processing

  1. FilePathsForLoop - Set folder path and extension (e.g., "C:/images", "*.png")
  2. Connect filepath to your image loader node (e.g., Load Image)
  3. Connect your processing nodes (e.g., filters, effects)
  4. Connect the final processing output to FilePathsEnsureExecution inputs
  5. Connect FilePathsForLoop's current_index to FilePathsLoopClose's current_index
  6. (Optional) Connect FilePathsEnsureExecution's output to FilePathsLoopClose's passthrough_1

This setup will automatically process each file in the folder sequentially.

Why Three Nodes?

  • FilePathsForLoop: Initiates the loop, provides file paths and metadata
  • FilePathsEnsureExecution: Optional helper to chain dependencies and ensure execution order
  • FilePathsLoopClose: Terminates the loop, provides completion signal, collects results

Installation

Place this folder in your ComfyUI custom_nodes directory and restart ComfyUI.

S
Description
No description provided
Readme MIT
692 KiB
Languages
Python 100%