Image from Dir Selector (Nich)
Pick a random image from a folder without touching the file dialog
- image
- filename
- filename_without_extension
You've got a folder of reference images and you want the workflow to grab one of them - any one of them - every time it runs. ComfyUI's built-in Load Image makes you click a file each run, which is exactly what you don't want when you're doing "give me a random IP-Adapter reference" or "cycle through ControlNet poses until something sticks." That's the hole this node fills: point it at a directory, and it hands you a random image from it, no dialog, no clicking.
This is one of two nodes in the tiny ComfyUI Nich Utils pack (nickve28), which the README itself flags as "still in early development! It will likely contain bugs or oddities." So it's a small, rough utility - but for the random-reference job it's genuinely handy, and it ships with zero extra dependencies.
How it works
Each time the graph executes, the node walks your directory, collects matching files, and picks one with a random.choice. A few details matter:
- It only picks from
.png,.jpg,.jpeg, and.webp- anything else is ignored even if it matches your regex. - The random generator is seeded per-node from OS entropy plus a timestamp, so your pick isn't coupled to ComfyUI's global seed. Two of these nodes in one graph won't pick the same image.
- It reloads the chosen file from disk with PIL and converts it to a standard ComfyUI image tensor (
[1, H, W, 3], RGB, floats 0–1), so it plugs straight into IP-Adapter, ControlNet preprocessors, or anywhere a Load Image output would go.
The clever bit is IS_CHANGED. By default it returns a fresh UUID every call, which tells ComfyUI "this node changed" - so it re-randomizes on every execution. Flip keep_current_selection on and it returns a constant instead, meaning the node stops re-running and your pick stays put while you fiddle with everything else in the graph. Note the pick lives in memory: restart ComfyUI and even a "kept" selection resets.
The inputs that matter
- directory - the folder to sample. Defaults to
~/images;~is expanded for you. - keep_current_selection - pin the current image so re-runs don't re-randomize. There's a quirk where toggling this from off to on still forces one fresh pick.
- include_subdirectories - walk subfolders too. Filenames come back as paths relative to
directory, so you can still tell where a pick came from. - regexp_filter - optional Python regex (
re.search) matched against the filename/path, handy for sampling only e.g.pose_files. Remember the extension check still applies on top.
Outputs: image (the tensor), filename (the relative path, e.g. subfolder/img.png), and filename_without_extension. The two string outputs are the workflow-friendly way to log which image you got - the README explicitly removed the old "selected image" text box because it was unstable, so wire the filename output into your save/notes if you want a record.
Install
Via ComfyUI Manager, search "ComfyUI Nich Utils". Or the manual way:
cd ComfyUI/custom_nodes
git clone https://github.com/nickve28/ComfyUI-Nich-Utils
Restart ComfyUI. No model files to download - requirements.txt lists torch, numpy, torchvision and Pillow, which any ComfyUI install already has. That "no extra dependencies" property is the best thing this pack has going for it.
Where people get burned
The realistic failure is an empty result: point it at a folder with no supported images, or a regex that matches nothing, and random.choice throws on an empty list. ComfyUI will show you a list index out of range-style error - fix it by checking the folder path and, if you filtered, testing the regex against a filename first. Otherwise, keep in mind it's per-node random, not seeded by anything you control, so if you need reproducibility for a shared workflow, you'll want to wire the filename output back in and record it rather than praying the seed lands.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| directory | STRING | ~/images | — |
| keep_current_selection | BOOLEAN | false | — |
| include_subdirectories | BOOLEAN | false | — |
| regexp_filteropt | STRING | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| filename | STRING | — |
| filename_without_extension | STRING | — |