dirname

Returns the directory portion of a file path, everything up to but not including the final path element.

A trailing slash means the final element is empty, so the path is returned without it, and a bare name with no directory yields "." so callers can join it back without special-casing.

InputArgumentsReturnsstringno argumentsstring
Source
BasicSource

Returns the directory portion of a path, everything up to but not including the final element.

Given

{"path": "docs/reports/q1.pdf"}

Template

{{ path | dirname }}

Result

docs/reports
AbsoluteSource

Keeps the leading slash for an absolute path.

Given

{"path": "/var/log/syslog"}

Template

{{ path | dirname }}

Result

/var/log
Bare nameSource

Returns "." when the path is a bare file name with no directory part, so it can still be joined back safely.

Given

{"path": "invoice.txt"}

Template

{{ path | dirname }}

Result

.