Nodes/LF Nodes/Load file from disk once
ComfyUI Node

Load file from disk once

Load each file exactly once — the batch-processing cheat code

By lucafoscili·Created 2 years ago·Updated 2 years ago· 50
Load file from disk once
  • ui_widget
  • file
  • name
  • file_list
  • name_list
dir
subdirfalse
strip_exttrue
enable_historytrue

Here's the batch problem no default node solves: you have a folder of 200 images, each needs processing, and you want every run to grab the next one instead of the same one. LF_LoadFileOnce is built for exactly that. It loads a file from disk and - thanks to a history mechanism - makes sure it doesn't load the same filename twice.

The pattern is dead simple and genuinely powerful. Point it at a directory, run the workflow, it hands you a file. Run it again, it hands you a different file. Run it 200 times and you've processed the whole folder, each run getting a fresh input with zero manual bookkeeping. For upscaling, captioning, or re-rolling a whole directory of images, this node is the difference between an afternoon of babysitting and a workflow that just walks the folder for you.

How it works

Four inputs shape the behavior. dir is the directory to scan. subdir (default off) includes subdirectories when on. strip_ext (default on) removes file extensions from the reported names. And enable_history (default on) is the heart of it - it records each executed file and date so the same filename never gets handed out twice, per the tooltip.

Outputs cover the two things you'll actually use:

  • file - the loaded file, typed as the generic * so ComfyUI routes it to whatever consumer (image, audio, text) fits. That's the whole point: the node doesn't care what kind of file it is.
  • name - the filename, for prompts, labels, or logging.
  • file_list / name_list - the same, as lists, for list-oriented chains.

Want it to pick a random file rather than the next one? That's a different node in this pack (there's a random file loader in the same family) - but for sequential, each-run-gets-a-new-file batch work, this is the one.

Installing it

It's part of LF Nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/lucafoscili/comfyui-lf

Restart ComfyUI, or install via ComfyUI Manager (search LF Nodes). No model downloads; just the pack's light Python dependencies.

Gotchas

The history is both the feature and the footgun. If you want to re-process a file - you fixed a bug and need to re-run image number three - the history will skip it. Toggle enable_history off for the re-run, or clear the history, and it'll load anything again. It's not random and it's not smart: it's "haven't I already done this one," which is exactly what you want until it isn't.

Pack note: comfyui-lf is legacy, frozen since Feb 2025; the author's active development is in lucafoscili/lf-nodes. The frozen build is stable and this node's logic is simple enough to be frozen forever without worry.

Category✨ LF Nodes/IO Operations

Inputs (5)

NameTypeDefaultDescription
dirSTRINGPath to the directory containing the images to load.
subdirBOOLEANfalseIndicates whether to also load images from subdirectories.
strip_extBOOLEANtrueWhether to remove file extensions from filenames.
enable_historyBOOLEANtrueEnables history, saving the execution value and date of the widget to prevent the same filename to be loaded twice.
ui_widgetoptKUL_HISTORY[object Object]

Outputs (4)

NameTypeDescription
file*
nameSTRING
file_list*
name_listSTRING