Nodes/ComfyUI-Mango-Random/随机文件路径
ComfyUI Node

随机文件路径

A random file off your disk, no filters attached

By mango-rgb·Created 2 years ago·Updated 2 years ago· 2
随机文件路径
    • STRING
    directory_path

    RandomFilePathNode is the simplest node in the Mango Random pack: give it a directory path, it hands you back a random file path as a string. That's the whole job. If you've ever wanted a workflow to reach into a folder and grab something different each run - a checkpoint, a LoRA, a config file, whatever - this is the blunt instrument for it.

    Here's the part the README doesn't tell you, straight from the source: there's no extension filter. The node walks the whole directory tree with os.walk, so it recurses into every subfolder, and it will happily pick dotfiles, temp files, and that .git blob if you point it at the wrong place. You get one input, directory_path (a plain STRING, default empty), and one STRING output. Nothing else. No seed, no mode, no sort - it's a single random.choice over whatever it found, every time it runs.

    Inputs and outputs

    • directory_path - the only thing you set. Give it a real absolute path like D:\style_refs or /home/user/comfy/models/loras. A wrong path raises NotADirectoryError; a path with no files raises FileNotFoundError, both as normal node errors.
    • STRING output - a full file path. Wire it into anything that accepts a path string: a checkpoint or LoRA loader, a VHS-style loader, or a custom loader that reads a path widget. Since it's just text, you can also pipe it through string nodes if a loader needs a filename instead.

    The node also declares IS_CHANGED as always-uncacheable, so it re-executes on every queue run. That's intentional - a random node that got cached would be a random node that never randomizes.

    How to install

    Standard pack install. Via ComfyUI Manager, search "Mango Random Nodes", Install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/mango-rgb/ComfyUI-Mango-Random-node
    

    then restart. No models to download. The requirements.txt lists opencv-python and imageio-ffmpeg, but this particular node uses neither - it's stdlib os and random only.

    Common issues

    Two things bite people. First, the no-filter behavior: point it at a curated folder, not your whole models directory, or you'll get random .txt sidecars and cache files instead of what you wanted. If you need an extension filter, this isn't the node - the sibling RandomImagePathNode only picks images.

    Second, there's no seed here, so there's no reproducing a specific pick. If you need "same path again," you'd have to cache the output yourself; for most uses that's fine, because the whole point is surprise.

    Honestly this node is a spare part. It's one function in a five-node pack, useful for a handful of automation cases, and thin enough that you'll outgrow it fast. But for "grab me a random file from this folder," it does exactly what it says.

    Category🥭 芒果节点/文件

    Inputs (1)

    NameTypeDefaultDescription
    directory_pathSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING