# locate-path

Learn how to find files matching a pattern.

This action finds files matching a glob pattern and stores the paths in a variable.

It is useful for discovering configuration files, checking whether a path exists before creating it, or finding source files to patch.

## Example

The following template locates the project's layout file and prints its path:

**template.json5**

```json5
{
  "$schema": "https://schema.croct.com/json/v1/template.json",
  "title": "Layout finder",
  "description": "Finds the root layout file.",
  "actions": [
    {
      "name": "locate-path",
      "path": "src/**/layout.{tsx,jsx}",
      "depth": 3,
      "limit": 1,
      "result": "layoutFiles"
    },
    {
      "name": "print",
      "semantics": "info",
      "message": "Layout file: ${this.layoutFiles[0]}"
    }
  ]
}
```

To apply this template, run:

```sh
croct use template.json5
```

## Properties

These are the supported properties:

- `name`: `string`

  The action identifier. Always `locate-path` for this action.

- `path`: `string`

  The glob pattern to match against file paths.

  For example, `**/*.ts` matches all TypeScript files and `src/components/*.tsx` matches TSX files in a specific directory.

- `result`: `string`

  The variable name to store the list of matching file paths.

  The result is a list of strings, where each entry is a relative path to a matched file.

- `limit`: `number` (optional)

  The maximum number of results to return.

  Must be a positive integer.

- `depth`: `number` (optional)

  The maximum directory depth to search.

  A depth of 0 matches only files in the current directory.

- `matcher`: `object` (optional)

  A content matcher to filter files by their content.

  The following examples show a pattern matcher that matches files containing a default function export, and a combination matcher that requires both a React import and a default export in the same file:

  **Pattern**

  ```json5
  {
    "pattern": "export default function",
    "caseSensitive": true
  }
  ```

  **Combination**

  ```json5
  {
    "type": "and",
    "matchers": [
      {"pattern": "import.*react"},
      {"pattern": "export default"}
    ]
  }
  ```

  - `pattern`: `string`

    The regular expression to match against the file content.

    For pattern matchers, specify this with [`caseSensitive`](#matcher-casesensitive-prop).

  - `caseSensitive`: `boolean` (optional) (default: false)

    Whether the pattern matching is case-sensitive.

    For pattern matchers, use this with [`pattern`](#matcher-pattern-prop).

  - `type`: `string`

    The logical operator to apply.

    Use `and` to require all nested matchers to match within the same file, or `or` to match files that satisfy at least one. For combination matchers, specify this with [`matchers`](#matcher-matchers-prop).

  - `matchers`: `Array<object>`

    The list of nested matchers to combine.

    Each entry can be a pattern matcher or another combination matcher, allowing nested conditions. For combination matchers, specify this with [`type`](#matcher-type-prop).

## Explore

- [Read file](/reference/cli/templates/actions/read-file): Learn how to read the located file.
- [Delete path](/reference/cli/templates/actions/delete-path): Learn how to delete the located path.
- [Move path](/reference/cli/templates/actions/move-path): Learn how to move the located path.
- [Define](/reference/cli/templates/actions/define): Learn how to store the path in a variable.
