💀Image from Folder by Index
Load one specific file from a scanned folder
- image
- mask
- filename
- width
- height
This is the "load one file" half of the S4Tool-Image pack's folder story. Where 💀Image from Folder scans a directory and returns a list of paths, 💀Image from Folder by Index takes that list and actually loads the image at position N. Together they're a deterministic batch loader: enumerate once, then grab files by number - the 3rd image, the 17th, whatever the workflow asks for.
The mechanism is a handshake: you feed it the filepaths string output from 💀Image from Folder, set an index (1-based), and the node parses the list, picks that entry, loads the file, and converts it to a tensor. It also derives a mask from the alpha channel and reports back the filename and dimensions - so you get both the pixels and the metadata in one shot. It's deliberately 1-indexed, which trips people who assume zero-based like Python lists.
Inputs and outputs
filepaths- the STRING output from 💀Image from Folder. This node doesn't scan on its own; it consumes someone else's scan.index- 1 to 9999, default 1. Which file to load.
Outputs:
image- the loaded IMAGE.mask- MASK from the alpha channel (opaque white if the file had no transparency).filename- the file's name, handy for logging or naming downstream outputs.widthandheight- the loaded image's dimensions as INTs.
Install
Same pack:
cd ComfyUI/custom_nodes/
git clone https://github.com/S4MUEL-404/ComfyUI-S4Tool-Image.git
pip install -r ComfyUI-S4Tool-Image/requirements.txt
Or ComfyUI Manager → search "S4Tool-Image" → Install → restart. Pure Pillow, no model downloads.
Gotchas
- It needs the
filepathsinput - feed it a raw folder path and it has nothing to index. This node is only useful wired to 💀Image from Folder. - 1-based, not 0-based - index 1 is the first file, matching how humans count and how the upstream node orders things.
- Out of range - an index beyond the list length fails or returns the fallback; keep
index≤ thecountoutput of the scanner node. - Order comes from the scanner - the index means nothing until you've decided the sort (filename/modified/size) on 💀Image from Folder. "The third file" is only well-defined because that node made the order deterministic.
If you're building a loop that walks a folder one image at a time - processing each file identically, in a stable order - this pair is the cleanest way to do it in pure nodes, no Python scripting required.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| filepaths | STRING | — | |
| index | INT | 11–9999 | — |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |
| filename | STRING | — |
| width | INT | — |
| height | INT | — |