Nodes/RisuTools/Load Last File Name Prefix
ComfyUI Node

Load Last File Name Prefix

Grab the newest file in a folder without typing its name

By tiamatiramisu·Created about a year ago·Updated about a year ago· 5
Load Last File Name Prefix
    • STRING
    directoryabsolute-path
    prefix

    Load Last File Name Prefix is the "give me the latest" node. Point it at a directory, give it a prefix, and it returns the filename - just the name, no path - of the most recently modified file that starts with that prefix. It's from RisuTools, the utility pack TiamaTiramisu wrote for integrating ComfyUI with RisuAI (the chat/roleplay frontend in SillyTavern's neighborhood), but its real use is anywhere you can't hardcode a filename ahead of time.

    Think hotfolders and loops. A script drops render_001.png, render_002.png… into a watched directory; you don't want to retype the name every run. You want "the newest one, whatever it's called." Same for picking up a freshly exported chat image or the latest file a bot left for you. In ComfyUI's normal world every input is typed by hand or chosen from a dropdown - this node turns "whatever just showed up" into a string you can wire onward.

    How it works

    Nothing clever, which is the point. It lists the directory, keeps files whose names start with prefix, sorts them by modification time, and returns the newest. The code is about a dozen lines and you can read all of it in the pack's nodes.py.

    One behavior to plan around: if nothing matches, it raises an error rather than returning something polite. There's no "not found" output to check - a miss is a hard failure that stops the queue. If your workflow needs to tolerate "no files yet," put Check File Name Prefix Exists (same pack) in front of it and branch on that BOOLEAN first.

    The node re-runs every execution (its IS_CHANGED returns a fresh random value), so it always re-scans the directory. That's exactly what you want for a "did something new arrive?" workflow - no stale cached filename.

    The two inputs that matter

    • directory (required) - absolute path to scan. The default is the placeholder "absolute-path"; type a real one.
    • prefix (optional, defaults to "") - empty means "newest file of any name in the directory."

    Output is a single STRING with the filename only. That's worth remembering: it's render_003.png, not /path/to/render_003.png.

    Putting it to work

    The intended loop is right inside the pack: feed this node's filename into Load Image From Text as its name input, and you've built "load the newest image in a folder" without ever naming a file. You can also wire the string into any node that takes a filename, or just print it. If you need the full path, you know the directory - join it yourself.

    Gotchas

    • "Newest" means most recently modified, so a file you touch without replacing jumps to the front. Usually fine; occasionally confusing.
    • Prefix matching is a case-sensitive startswith - render matches render_001.png and also renderer.png.
    • It returns the bare filename, so don't hand it to a node expecting a full path.
    • No match equals an error, not a False.

    Installing it

    It's one of four nodes in RisuTools, so install the pack once. ComfyUI Manager → search RisuTools → Install → restart, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TiamaTiramisu/risutools
    

    Then restart ComfyUI. Dependencies are just pillow and numpy - already in your environment, no downloads, no models. The pack is early-stage (version 0.0.1, one commit, placeholder README), but this node's whole body is short enough to eyeball for yourself, which is more than you can say for a lot of custom nodes.

    CategoryRisuTools/File

    Inputs (2)

    NameTypeDefaultDescription
    directorySTRINGabsolute-path
    prefixoptSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING