File Path Selector From Directory (Buff)
Hand your workflow a random (or next) file from a folder
- file_path
If you've ever sat in front of a ComfyUI workflow thinking "I wish it would just grab a random video from this folder and process it," this node is the answer. It scans a directory, filters by extension, and hands back a single file path - either a random one (seeded, so you can reproduce it) or the next one in alphabetical order, remembering where it left off between runs.
It sits in the utility layer, the 70% of every workflow that touches no pixels. Its job is to be a file source: something you feed into a video or image loader downstream. The two genuinely useful patterns are batch workflows that chew through a folder one file at a time, and "give me something different every run" workflows - random reference images, random input clips, random anything.
How it works
The directory gets walked (recursively if include_subdirectories is on), files are matched against your extension list case-insensitively, and the matching list is cached for cache_duration seconds so repeat runs don't rescan the disk. In randomize mode it seeds Python's random with your seed and picks an index - same seed plus same directory equals same file, which is the reproducibility guarantee. In sequential mode it keeps a per-directory index and walks the list in order, wrapping around at the end.
Here's the neat part: the sequential position is persisted to a file_selector_indices.json file in ComfyUI's working directory. Restart ComfyUI, come back tomorrow, and it remembers which file it handed you last time. That's the "process a folder over many sessions without losing your place" workflow made trivial. (The index is a class variable in the pack, so multiple nodes of this type in one graph each track their own key by directory path.)
The inputs that matter
directory_path- where to look. Defaults to ComfyUI's input directory.file_types- comma-separated extensions, no dots needed. The default ismp4,mkv,webm, so for images you'll want to change it to something likepng,jpg.selection_mode-randomizeorsequential. This is the whole personality of the node.seed- only relevant in randomize mode; 0 with a fresh random draw isn't reproducible.cache_duration- seconds to cache the file list; 0 disables caching. If you're dropping files into the folder live and want them picked up, you may want a short cache.
The one output is file_path, a plain string. Wire it into a loader that takes a path - or into a string consumer that feeds a filename downstream.
Install
It's part of BuffMcBigHuge's QoL pack. ComfyUI Manager, search "ComfyUI-Buff-Nodes", or:
cd ComfyUI/custom_nodes
git clone https://github.com/BuffMcBigHuge/ComfyUI-Buff-Nodes
Restart after cloning. No dependencies beyond what ComfyUI ships, no model downloads.
Gotchas
The usual suspects: a bad directory prints a warning and returns an empty string (so downstream nodes get "" and may fail in confusing ways - check the console), and "no matching files" does the same. Paths come back absolute and unquoted, which is what you want to feed loaders. One subtle thing: the pack writes file_selector_indices.json into the working directory it was launched from, so if you're running ComfyUI as a service, that's where your sequential state lives. It's a small, single-purpose node - but for folder-crawl automation it's exactly the thing you'd otherwise hand-roll.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| directory_path | STRING | /tmp/ComfyUI/input | Path to the directory containing files to select from. Can be absolute or relative path. |
| file_types | STRING | mp4,mkv,webm | Comma-separated list of file extensions to include (e.g., 'mp4,jpg,png'). No dots needed. |
| selection_mode | COMBO | randomize | randomize: Pick a random file each time (can be seeded) sequential: Go through files in order, remembering position between sessions |
| include_subdirectories | COMBO | True | When True, searches in subdirectories for matching files. When False, only searches in the specified directory. |
| seedopt | INT | 00–18446744073709550000 | Seed for random selection. Use the same seed to get the same file each time. |
| cache_durationopt | INT | 600–3600 | How long to cache the file list in seconds. 0 disables caching. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| file_path | STRING | — |