read-file

Learn how to read file content into a variable.

This action reads the content of a file and stores it in a variable.

The content is available as a string for use in subsequent actions, such as printing, patching, or conditional logic.

Example

The following template reads a file and prints its content:

template.json5
{  "$schema": "https://schema.croct.com/json/v1/template.json",  "title": "File reader",  "description": "Reads and displays a file.",  "actions": [    {      "name": "read-file",      "path": "README.md",      "result": "content"    },    {      "name": "print",      "semantics": "info",      "message": "${this.content}"    }  ]}

To apply this template, run:

npx croct@latest use template.json5

Properties

These are the supported properties:

name
string

The action identifier. Always read-file for this action.

path
string

The path to the file to read.

result
string

The variable name to store the file content as a string.

optional(optional)
boolean

Whether to store null instead of failing when the file does not exist or is a directory.

Default:false