Nodes/ComfyUI-FilePathsFromFolder/File Paths For Loop Start
ComfyUI Node

File Paths For Loop Start

Run your graph once per file, the lazy way

By RockyHong·Created 7 months ago·Updated 7 months ago· 1
File Paths For Loop Start
    • current_filepath
    • current_filename
    • current_index
    • total_file_count
    folder_path
    extension*.png

    This is the node the whole ComfyUI-FilePathsFromFolder pack is quietly built around: "File Paths For Loop Start." You give it a folder and an extension, and it makes ComfyUI run your downstream graph once per file - no external loop pack required. It's the "I just want to process 400 PNGs" node, and for a beginner it's by far the friendliest entry point into the pack.

    The trick, and it's a genuinely neat one, is that this node doesn't actually loop anything itself. It returns lists - one entry per file - and declares OUTPUT_IS_LIST on all four of its outputs. That's the ComfyUI-native mechanism where a node outputs a batch and every downstream node executes once per item in that batch. The node's own docstring says it "iterates through files one at a time," which is true from your seat at the graph; the engine is just doing list batching under the hood.

    The inputs

    Same two-string pair as LoadFilePathsFromFolder:

    • folder_path - the folder to scan, as an absolute path.
    • extension - a glob pattern, default *.png. *.jpg, *.mp4, *.txt, *_v2.png all work, and it's top-level only - no subfolder recursion.

    The outputs (all lists)

    • current_filepath - full path of the current file, per iteration. Feed this into your Load Image / Load Video / Load Audio.
    • current_filename - the base name without extension (cat_003). Great for output naming.
    • current_index - 0, 1, 2… per iteration. This is what you feed to File Paths For Loop End to close the loop.
    • total_file_count - the same number repeated on every item. Boring, but handy for progress math or a denominator.

    How to wire it

    The README's flow: current_filepath → your loader → your processing nodes → current_indexFile Paths For Loop End. The End node is not optional decoration - it's what tells ComfyUI the loop is closed and counts what got processed. If you have save/write/export nodes that must actually run (more on that in the FilePathsEnsureExecution article), anchor them through the ensure-execution node and connect that into the End node's passthrough.

    The memory gotcha you should read twice

    Because this is list batching and not a true per-file loop, ComfyUI may run all loads, then all processing, then all saves instead of finishing file 0 completely before starting file 1. The README is refreshingly honest about this: intermediate results can pile up in RAM/VRAM, and memory can climb on big folders. It's great when you're processing many files with the same model - the model stays "warm" and you avoid reload/offload churn per file. It's less great when a folder is big enough that holding every intermediate latent is uncomfortable.

    If you need true one-file-at-a-time (each file start-to-finish, cleanup included), don't fight this node - use an external loop pack instead, or pair LoadFilePathsFromFolder + GetPathByIndex with one you already run. That's the honest split this pack offers you, and it's nice to have the choice.

    Install and sanity checks

    cd path/to/ComfyUI/custom_nodes
    git clone https://github.com/RockyHong/ComfyUI-FilePathsFromFolder.git
    

    Restart, then find "File Paths For Loop Start." No dependencies, no models, nothing to download - the entire pack is Python stdlib. Search the node menu for the display name, not the class, if it's not obvious. And if your workflow returns nothing at all, check the folder path and extension first: an empty folder makes the node return empty lists, which silently produce zero iterations rather than an error.

    CategoryFilePathsFromFolder/Loop

    Inputs (2)

    NameTypeDefaultDescription
    folder_pathSTRING
    extensionSTRING*.png

    Outputs (4)

    NameTypeDescription
    current_filepathSTRING
    current_filenameSTRING
    current_indexINT
    total_file_countINT