索引选择器
Pick one path out of a list and get its filename for free
- selected_path
- file_name
- last_folder
The Path Collector hands you a multi-line string of paths, and half the time you only want one of them. Index Selector is the node that plucks a single line out of that string by number - and unlike a plain text split, it also does the filename and folder dissection for you while it's at it. In this pack it's the little helper that turns "a folder full of reference images" into "this specific reference image, named and organized."
You feed it a combined_string (a multi-line path string - the natural source is PathCollectorNode, though any text works) and an index (0-based: 0 is the first line, 1 the second). It outputs three things:
selected_path- the raw path you picked.file_name- the file's basename without its extension (ref_01fromref_01.png).last_folder- the name of the last directory. For a file path it's the parent folder's name; for a directory path it's that directory's own name.
That last output is the sleeper feature. In the pack's WanAnimate multi-ref workflow, reference images are organized in folders by character or angle, and last_folder is how a downstream node knows which subject a given image is without parsing paths. It also handles the file-vs-folder ambiguity sensibly: it checks the filesystem when possible, and falls back to a heuristic (trailing slash or extension) when the path doesn't exist yet.
What you set
Just index, and only if you're not wiring it from somewhere. If the index is out of range, all three outputs come back as empty strings - no crash, just nothing, so gate downstream logic on non-empty rather than assuming.
When you'd reach for it
- Selecting one reference image out of a collected batch by position.
- Grabbing
last_folderto tag which character folder a frame came from. - Anywhere you have a list-as-string and need element N plus its parts. It's unglamorous plumbing (see the KB's node-plumbing doc for why the ecosystem is full of exactly these), but it's plumbing that saves you a string-parsing node you'd otherwise hand-roll.
Install
Part of user2318/ComfyUI-CustomNodeKit. ComfyUI Manager: search "CustomNodeKit". Or:
cd ComfyUI/custom_nodes
git clone https://github.com/user2318/ComfyUI-CustomNodeKit.git
cd ComfyUI-CustomNodeKit
pip install -r requirements.txt
then restart. No models, no downloads - it's str.split with extras.
The gotcha
Mind the off-by-one: this node is 0-based, while its sibling PathCollectorNode's index param is 1-based (where 0 means "all lines"). Feed Path Collector's index 1 into this node expecting the same line and you'll get the second line, not the first. Different conventions in the same pack, both documented, both a classic source of "why is it picking the wrong image?" Also, if a path is a directory that doesn't exist yet, the heuristic kicks in and the extension check decides it's a folder - fine in practice, just don't feed it a not-yet-created file and expect file_name to fill in.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| combined_string | STRING | 来自路径收集器或其他来源的多行路径字符串,每行一个路径。Multi-line path string from the path collector, one path per line. | |
| index | INT | 00–1000 | 选择第几条路径(从0开始)。超出范围时输出为空。Select which path by index (starting from 0). Outputs empty if out of range. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| selected_path | STRING | — |
| file_name | STRING | — |
| last_folder | STRING | — |