ComfyUI-Get-Random-File Introduction
ComfyUI-Get-Random-File adds nodes for choosing files and images from folders, retrieving an image by its index, and saving images or videos to a folder you choose. It can help you build workflows that try different source images or work with files outside ComfyUI’s usual output folder.
Some nodes return a file path, which is the location of a file on your computer. The image-selection nodes also return an IMAGE you can connect to another node. Those two outputs serve different purposes: use the image when the next step needs to work with its pixels, and use the path when the next step needs to know where the file came from.
How ComfyUI-Get-Random-File Works
Think of a folder as a collection of source material for a project. Random File Path chooses one file from that collection and tells the rest of your workflow where it is. Random Image Path does something similar for an image, but also supplies the image itself. When you need to select an image by its position in a folder instead of making a random choice, use Get Image File By Index.
The image-selection nodes can also read prompts stored in an image’s embedded ComfyUI workflow metadata. For example, if you select a PNG created by a ComfyUI workflow, you may be able to pass its original positive and negative prompts to later nodes. If the selected image has no embedded prompts, those outputs are empty.
The saving nodes handle the other end of a workflow: they write a resulting image or video to a folder on your computer.
ComfyUI-Get-Random-File Features
- Random File Path chooses a random file from a specified directory and returns its path as a
STRING. Use it when another node needs a file location rather than an image loaded into the workflow. - Get Image File By Index retrieves an image from a specified directory by index. It returns the
IMAGEand its file path as aSTRING, giving you both the image to process and its location. - Random Image Path chooses a random image file from a directory. It returns the
IMAGEand its file path as aSTRING, making it useful when you want to vary the source image used by a workflow. - Prompt metadata outputs are available on Random Image Path and Get Image File By Index. Each provides
positive_promptandnegative_promptstrings extracted from embedded ComfyUI workflow metadata when available. The author describes support for prompts found through titled prompt nodes, sampler or guider connections, parallel chains, injected graphs, combined preparation nodes, several ComfyUI text encoders, and text-concatenation or wildcard nodes. An image without embedded prompts, or a non-PNG image, returns empty prompt strings. - Save Image to Folder saves images to a folder you choose, including one outside ComfyUI’s output directory. It creates the folder if needed and uses a numbered, stock-style
_00001_counter to avoid overwriting an existing file. PNG saves embed workflow metadata. The node also supports stock prefix variables such as%width%and%datefor naming output files. - Save Video to Folder saves a
VIDEOinput to a folder you choose using ComfyUI’s video writer. Compatible streams are copied; the video is re-encoded when the requested format, codec, or CRF requires it.
Node previews
Random File Path
Random Image Path
Get Image File By Index
Get Image File By Index preview
The original README also includes a preview labeled “Get Video By Index”, but does not describe that node’s inputs or outputs.
Troubleshooting ComfyUI-Get-Random-File
I expected an image, but I only have a file path. What should I use?
Check which node you selected. Random File Path returns a path as a STRING; it does not return an IMAGE. Use Random Image Path for a random image, or Get Image File By Index to retrieve an image by index.
Why are the positive and negative prompt outputs empty?
First, check whether the selected image is a PNG with embedded ComfyUI workflow metadata. The author notes that images without embedded prompts and non-PNG files return empty strings. An empty output does not necessarily mean that image selection failed.
How do I keep a new image from replacing an earlier result?
Use Save Image to Folder. Its numbered filename counter avoids overwriting existing files.
Can I save outside ComfyUI’s usual output directory?
Yes. Save Image to Folder and Save Video to Folder are described as accepting a folder anywhere on your computer. Save Image to Folder also creates its destination folder if it does not exist.
Why might saving a video take longer than simply copying it?
Save Video to Folder copies compatible streams, but re-encodes when the chosen format, codec, or CRF requires it.
Learn More about ComfyUI-Get-Random-File
Visit the ComfyUI-Get-Random-File repository for the project’s README and node previews. The previews can help you recognize the nodes when assembling an image-selection workflow.
