Nodes/comfy-ovum/os.path.dirname
ComfyUI Node

os.path.dirname

Strip the filename, keep the folder — os.path.dirname as a node

By sfinktah·Created about a year ago·Updated 10 months ago· 7
os.path.dirname
  • path_in
  • path
path
forward_slashesfalse

Ovum Os Path Dirname wraps os.path.dirname: hand it C:\ComfyUI\output\render_00042.png and it returns C:\ComfyUI\output - everything before the last path separator. It's the inverse of the pack's basename node (which keeps the file and drops the folder), and together they're the two most-reached-for path operations in any file-driven workflow.

You need this whenever a filename gets in the way of where the file lives. Build an output directory from a known file. Resolve the folder for a Save Image destination. Compare whether two files share a directory. Or feed the result into OvumCombinePaths to assemble a list of paths all under one folder. It's one of those nodes that feels trivial until the moment you're mid-graph without a way to get the directory out of a full path.

How it works

Same pattern as the whole os.path family: a path text widget plus an optional path_in jack (accepting PATHLIKE or STRING) that overrides the widget when connected. The node calls os.path.dirname() and returns the folder as a string. Pure string logic - no filesystem access, no existence check. The forward_slashes toggle normalizes any backslashes in the result to forward slashes, which is handy when you're handing paths to something cross-platform.

The inputs and outputs that matter

  • path (required, STRING) - the full path.
  • path_in (optional, PATHLIKE,STRING) - wired alternative to the widget.
  • forward_slashes (BOOLEAN, default false) - normalize separators in the output.
  • path (output, STRING) - the directory portion.

Installing it

In comfy-ovum (sfinktah). ComfyUI Manager: search "comfy-ovum", install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/sfinktah/comfy-ovum

Restart after. No models to download; the pack's dependencies are light (pillow, numpy, requests, aiohttp, etc.) and Manager installs them.

Common issues

Standard-library edge cases apply. A path with no directory (a bare filename like render.png) returns an empty string, not . - surprising if you expected a fallback. And trailing separators are significant: C:\out\ dirname is C:\out per Python's rules. Since there's no validation, a malformed string gives you a deterministic but possibly wrong folder; if you need the canonical folder (symlinks resolved), pair this with OvumOsPathRealpath or use abspath first.

Categoryovum/path/os.path

Inputs (3)

NameTypeDefaultDescription
pathSTRING
forward_slashesBOOLEANfalse
path_inoptPATHLIKE,STRING

Outputs (1)

NameTypeDescription
pathSTRING