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
Recommended: Git clone
- Clone into
ComfyUI/custom_nodes
cd path/to/ComfyUI/custom_nodes
git clone https://github.com/RockyHong/ComfyUI-FilePathsFromFolder.git
- Restart ComfyUI
- Search nodes by name:
Load File Paths From Folder,Get File Path By Index,File Paths For Loop Start
Alternative: Manual install (ZIP)
- Download ZIP from GitHub
- Extract
- Copy folder
ComfyUI-FilePathsFromFolderintoComfyUI/custom_nodes/ - Restart ComfyUI
Choose how you want to iterate
-
Option A — External loop (index-based): get a file path list + pick one path per iteration (jump)
- Use
LoadFilePathsFromFolder→GetPathByIndex(UI:Load File Paths From Folder→Get File Path By Index) - Best when you already have a loop/for/while node from another pack, and you just need a clean “files-by-extension” input.
- Use
-
Option B — This repo’s loop node: run downstream nodes once per file (list batching) (jump)
- Use
FilePathsForLoop→ your processing nodes → (optional)FilePathsEnsureExecution→FilePathsLoopClose - UI:
File Paths For Loop Start→ your processing nodes → (optional)File Paths Loop Ensure Execution→File Paths Loop End - Best when you want a simple, no-extra-deps “loop”: ComfyUI runs downstream nodes once per file via list batching.
- Use
Option A — External loop (index-based)
Use this when you already have an external loop/for/while node pack and you want to drive it with “files in a folder” (by extension).
Nodes used
LoadFilePathsFromFolder: scan folder → getfilepaths/filenames/countGetPathByIndex: choose one item → getfilepath/filename(UI:Get File Path By Index)
Example workflow (external loop pack)
LoadFilePathsFromFolder(set folder path + extension)count→ your loop node “iterations” / “max” (names vary by pack)- Loop
index→GetPathByIndex.index LoadFilePathsFromFolder.filepaths+.filenames→GetPathByIndexGetPathByIndex.filepath→ your loader node (Load Image / Load Video / etc.)- Do your processing + save/export inside your external loop pack
Node reference
LoadFilePathsFromFolder
- Parameters
folder_path: folder to scanextension: pattern like"*.png","*.jpg","*.txt"
- Outputs
filepaths: newline-separated full pathsfilenames: newline-separated base names (no extension)count: number of matched files
GetPathByIndex
- Inputs
filepaths: fromLoadFilePathsFromFolderfilenames: fromLoadFilePathsFromFolder
- Parameter
index: 0-based index
- Outputs
filepath: selected full pathfilename: selected base name
Option B — Internal loop (this repo’s loop node, list batching)
Use this when you want the simplest setup: FilePathsForLoop returns lists, and ComfyUI runs downstream nodes once per file via list batching. (UI: File Paths For Loop Start)
Nodes used
FilePathsForLoop: generates the per-file list outputs (current_filepath,current_index, etc.) (UI:File Paths For Loop Start)- (Optional)
FilePathsEnsureExecution: “anchors” a route so it definitely runs (useful for save/write/export routes) (UI:File Paths Loop Ensure Execution) FilePathsLoopClose: loop terminator / completion signal (UI:File Paths Loop End)
Memory note
FilePathsForLoop uses ComfyUI list batching (it sets OUTPUT_IS_LIST). This is not a “while/for loop” that runs one full item end-to-end.
- What you may observe: ComfyUI often runs node-by-node for the batch. So a route like
Load X From Path→Process→Savecan look like “all loads”, then “all processing”, then “all saves” (not Load→Process→Save per file). - Why memory can grow: batching can keep more intermediate results “alive” until later nodes run; heavy nodes (models / large frames / big tensors) can push VRAM/RAM peak usage.
- Practical tip: if you notice memory climbing, add “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 an external loop/for/while node pack and Option A.
Example workflow (internal loop: once per file)
FilePathsForLoop(set folder path + extension)current_filepath→ your loader node (e.g. Load Image)- Your processing nodes
- (Optional) outputs you want to guarantee run (e.g. save/write/export nodes) →
FilePathsEnsureExecution.passthrough_1…passthrough_5 current_index→FilePathsLoopClose.current_index- (Optional)
FilePathsEnsureExecution.passthrough→FilePathsLoopClose.passthrough(this “anchors” the route so it executes)
Node reference (internal loop nodes)
FilePathsForLoop
- Parameters
folder_pathextension
- Outputs (all are lists)
current_filepathcurrent_filenamecurrent_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).
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.
FilePathsLoopClose
- Inputs
current_index: fromFilePathsForLoop(required)passthrough: optional (often fromFilePathsEnsureExecution.passthrough)
- Outputs
processed_count
License
MIT — see LICENSE.
.jpg)
.jpg)