2026-01-25 13:29:55 +08:00
2026-01-25 03:18:27 +08:00
2026-01-25 12:31:20 +08:00
2026-01-25 12:33:23 +08:00
2026-01-25 13:29:55 +08:00

ComfyUI-FilePathsFromFolder

Load file paths from a folder by extension (*.png, *.mp4, *.txt, etc.), then feed them into any ComfyUI node that accepts a path (image/video/audio/anything-from-path).

This repo is mainly for easy batch processing:

  • Use it with your favorite loop/for/while node pack (pick items by index), or
  • Use this repo’s simple loop node (FilePathsForLoop) to have ComfyUI run downstream nodes once per file (list batching).

Installation

  1. Clone into ComfyUI/custom_nodes
cd path/to/ComfyUI/custom_nodes
git clone https://github.com/RockyHong/ComfyUI-FilePathsFromFolder.git
  1. Restart ComfyUI
  2. Search nodes by name: LoadFilePathsFromFolder, GetPathByIndex, FilePathsForLoop

Alternative: Manual install (ZIP)

  1. Download ZIP from GitHub
  2. Extract
  3. Copy folder ComfyUI-FilePathsFromFolder into ComfyUI/custom_nodes/
  4. Restart ComfyUI

Choose how you want to iterate

  • Option A — Use another loop pack (index-based): get a file path list + pick one path per iteration

    • Use LoadFilePathsFromFolder → GetPathByIndex
    • Best when you already have a loop/for/while node from another pack, and you just need a clean “files-by-extension” input.
  • Option B — Use this repo’s simple loop: run downstream nodes once per file (list batching)

    • Use FilePathsForLoop → your processing nodes → (optional) FilePathsEnsureExecution → FilePathsLoopClose
    • Best when you want a simple, no-extra-deps “loop”: ComfyUI runs downstream nodes once per file via list batching.

Node reference

LoadFilePathsFromFolder

  • What it does: scan a folder for matching files.
  • Parameters
    • folder_path: folder to scan
    • extension: pattern like "*.png", "*.jpg", "*.txt"
  • Outputs
    • filepaths: newline-separated full paths
    • filenames: newline-separated base names (no extension)
    • count: number of matched files

GetPathByIndex

  • What it does: pick one file by index (0-based).
  • Inputs
    • filepaths: from LoadFilePathsFromFolder
    • filenames: from LoadFilePathsFromFolder
  • Parameter
    • index: 0-based index
  • Outputs
    • filepath: selected full path
    • filename: selected base name

Loop nodes (ComfyUI list batching)

Memory note (about this repo’s loop nodes)

FilePathsForLoop uses ComfyUI list batching (it sets OUTPUT_IS_LIST). This is not a “while/for loop” that runs one full iteration end-to-end.

  • What this means in practice: if you connect Load X From Path → Process → Save, ComfyUI may do all the Load work for the batch first, then all the Process work, then all the Save work (instead of Load→Process→Save per item).

  • Why memory can grow: batching can keep more intermediate results “alive” until later nodes run, and heavy nodes (generation/model processing/large video frames) can push VRAM/RAM peak usage.

  • Why batching can be great: big models can stay loaded while the batch runs, so you avoid repeated load/unload overhead between items.

  • Practical tip: if you notice memory climbing, insert “Clean VRAM” / “Clean RAM” (or equivalent) at safe points after heavy steps.

  • If you need strict sequential iteration (finish item 0 completely before item 1): use a dedicated for/while-loop node pack (a “real loop”), and drive it with:

    • LoadFilePathsFromFolder → count (loop count)
    • GetPathByIndex → filepath/filename (per-iteration selection)

FilePathsForLoop

  • What it does: returns a list of files so ComfyUI can run downstream nodes once per item.
  • Parameters
    • folder_path
    • extension
  • Outputs (all are lists)
    • current_filepath
    • current_filename
    • current_index (0-based)
    • total_file_count

Key detail: this node sets OUTPUT_IS_LIST. Downstream nodes receive one item per execution (not the whole list).

FilePathsLoopClose

  • What it does: loop “terminator” / completion signal.
  • Inputs
    • current_index: from FilePathsForLoop (required)
    • passthrough: optional (often from FilePathsEnsureExecution.passthrough)
  • Outputs
    • processed_count

FilePathsEnsureExecution

  • What it does: “collects” outputs so a route becomes required (and actually runs).

ComfyUI schedules execution based on dependencies: if nothing downstream “needs” a route’s results, ComfyUI may skip that route (or only run part of it).

FilePathsEnsureExecution is a simple way to guarantee a route runs: plug the outputs you care about into passthrough_1…passthrough_5, then plug passthrough into FilePathsLoopClose.passthrough so the graph depends on that route.

Practical rule of thumb: you usually only need to connect the terminal node/output of the route you want to guarantee (the last node in that route). If the end node must run, everything upstream of it becomes required too.

Example route: Load Image From Path → processing → Save Image → connect the Save Image output to FilePathsEnsureExecution.passthrough_* to “anchor” the whole chain.

  • Inputs
    • passthrough_1 … passthrough_5: any type (*)
  • Outputs
    • passthrough: first non-None input

Tip: if you need more than 5 inputs, chain multiple FilePathsEnsureExecution nodes.

How ComfyUI list batching works (tiny mental model)

When a node outputs a list (via OUTPUT_IS_LIST):

  1. The node returns something like ["file1.png", "file2.png", "file3.png"]
  2. ComfyUI schedules execution across the graph in batch mode
  3. Many nodes will be invoked repeatedly so each call receives a single item (e.g. "file2.png")
  4. But execution tends to happen node-by-node for the batch (so you may observe “all loads”, then “all processing”, then “all saves”)

Example workflow (loop every file)

  1. FilePathsForLoop (set folder path + extension)
  2. current_filepath → your loader node (e.g. Load Image)
  3. Your processing nodes
  4. (Optional) outputs you want to guarantee run (e.g. save/write/export nodes) → FilePathsEnsureExecution.passthrough_1 … passthrough_5
  5. current_index → FilePathsLoopClose.current_index
  6. (Optional) FilePathsEnsureExecution.passthrough → FilePathsLoopClose.passthrough (this “anchors” the route so it executes)
S
Description
No description provided
Readme MIT
692 KiB
Languages
Python 100%