dirname
Learn how to extract the directory from a path.
Returns the directory portion of a path, stripping the filename.
Example
The following template extracts and prints the directory from a file path:
template.json5
{ "$schema": "https://schema.croct.com/json/v1/template.json", "title": "Dirname demo", "description": "Prints the directory from a path.", "options": { "path": { "type": "string", "description": "The file path.", "default": "src/components/Card.tsx" } }, "actions": [ { "name": "print", "message": "Directory: ${dirname(options.path)}" } ]}With the default value, this prints Directory: src/components.
Parameters
- pathstring
The file path to extract the directory from.
Return
The directory portion of the path.
For example, dirname('src/components/Button.tsx') returns src/components. If the path has no directory part, returns ..