Nodes/ComfyUI-JNodes/Get Leaf Directory
ComfyUI Node

Get Leaf Directory

Grab the last folder name from a path

By JaredTherriault·Created 3 years ago·Updated about a month ago· 91
Get Leaf Directory
    • STRING
    path

    Give it a path and it returns the last folder in it - the "leaf." From /renders/2026/client_project/wan_batch/, you get wan_batch. That final directory name is often the meaningful label in a path: the batch name, the project, the category you organized things under. Get Leaf Directory pulls it out as a string so you can reuse it - name your outputs after the source folder, tag metadata with the project name, or branch logic on which directory something came from.

    It pairs naturally with the pack's other path helpers. Where Get Clean Filename extracts the file's name, this extracts the folder's name, and together they let you take a full path apart and rebuild it however you want. Small, unglamorous, exactly the kind of glue a tidy automated workflow is made of.

    How it works

    Pure string parsing. It splits the path on directory separators and returns the last directory segment. No disk access - it reads the text of the path, so it doesn't care whether the folder actually exists. Feed it a path with a trailing file and it returns the folder that file sits in; feed it a folder path and it returns that folder's own name.

    The inputs and outputs that matter

    • path - the path string to parse. Single-line. Usually wired from a loader's path output, Get Comfy Directory, or another path-producing node.

    The output is a single STRING - the leaf directory name - into a filename builder, a metadata writer, or a display.

    How to install it

    ComfyUI Manager, search JNodes, install, restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/JaredTherriault/ComfyUI-JNodes
    pip install -r ComfyUI-JNodes/requirements.txt
    

    No models.

    Common issues & troubleshooting

    Got a filename instead of a folder. If your path ends in a file (.../wan_batch/clip.mp4), what counts as the "leaf" depends on how the path is structured - you may want the containing folder, not the file. Preview the output to see what it returned, and if you actually wanted the file's name, use Get Clean Filename instead.

    Trailing slash changes the answer. A path ending in / versus not can shift what the last segment is. If results look off by one level, check whether your input path has a trailing separator and normalize it upstream.

    Empty output. The input was empty or had no separators to split on. Confirm a real path string is reaching the input.

    Mixed slashes. Backslash (Windows) versus forward-slash (Unix) paths can confuse naive splitting when a path crosses platforms. Normalize the separators upstream if you're moving paths between systems.

    Categorysd

    Inputs (1)

    NameTypeDefaultDescription
    pathSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING