Nodes/ComfyUI_BadgerTools/GetDirName-badger
ComfyUI Node

GetDirName-badger

Pull the folder name out of a path — the file-helper you'll forget you needed

By AbyssBadger0·Created 3 years ago·Updated 2 years ago· 8
GetDirName-badger
    • STRING
    dir_path

    Give GetDirName-badger a path and it hands you back the last component - the folder's own name. /data/runs/hero_v2/framesframes. It's os.path.basename exposed as a graph node, which is the most unglamorous sentence in this whole pack, and also one of the most honestly useful ones for anyone doing file-organized work in ComfyUI.

    The file-helper cluster in ComfyUI_BadgerTools exists because the author clearly works in directories, not single outputs: there's getParentDir-badger (go up one level), mkdir-badger (make a subfolder), GetUUID-badger (unique names), and deleteDir-badger (clean up after yourself). GetDirName is the read-only cousin - the one that tells you which directory you're in. And "which directory am I in?" is a real question when your path is being assembled dynamically across nodes instead of typed once.

    The classic pattern: a loop or batch writes into per-run subfolders, a node hands you back a full path (like FrameToVideo-badger returning its output path, or VideoToFrame-badger returning the frame folder), and you want to name something after that folder - a save filename, a prompt tag, a label. Extract the dir name, concatenate it into a string, done. It also pairs with getParentDir to walk a path upward: filename → folder → parent, each level one node.

    How it works

    Straight Python: os.path.basename() on the absolute version of the input. Trailing slashes are stripped first, so /data/runs/hero/ gives you hero, not an empty string - a small correctness detail that saves you a head-scratcher. Relative paths get resolved to absolute first, which means the node's answer is stable regardless of where ComfyUI is running from.

    Inputs and outputs

    • dir_path - a STRING path. This is the only input, and the only one that matters.

    One output: a STRING, the basename of the path.

    Installing it

    Part of ComfyUI_BadgerTools. ComfyUI Manager → search "BadgerTools" → install, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/AbyssYuan0/ComfyUI_BadgerTools
    

    Restart after install. No model files. And yes - this trivial string node still drags in the pack's heavyweight requirements (moviepy, open_clip, scikit-image…) at startup, because the pack imports its video module unconditionally. It's the tax you pay for the file helpers.

    Gotchas

    • It wants a folder path, not a file path. Give it /data/out/img.png and you get img.png - basename doesn't know or care that you meant the directory. If you meant the containing folder, use getParentDir-badger first.
    • It reads, it doesn't verify. The folder doesn't have to exist for the name to come back. That's usually fine; worth knowing if you were hoping it doubled as an existence check. It doesn't.

    No community threads exist for a node this small - it's a personal-pack string utility with a two-line README. But file-driven workflows are exactly where ComfyUI's type system is clunkiest, and a dedicated path-name node is a genuinely better answer than regex-hacking a string node to do the same thing.

    Categorybadger

    Inputs (1)

    NameTypeDefaultDescription
    dir_pathSTRING

    Outputs (1)

    NameTypeDescription
    STRINGSTRING