> ## Documentation Index
> Fetch the complete documentation index at: https://docs.alumio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Filesystem: Resolve destination filename conflict

> Ensures a destination path is available on the filesystem. If a file already exists at the path, applies a conflict resolution strategy (for example, appending a counter: foo.json becomes foo-2.json).

export const FormField = ({property, label, required = false, diType, uiPatterns, children}) => {
  const patterns = Array.isArray(uiPatterns) ? uiPatterns : uiPatterns ? [uiPatterns] : [];
  return <div style={{
    margin: '1.5rem 0'
  }}>
      <div style={{
    display: 'flex',
    alignItems: 'baseline',
    flexWrap: 'wrap',
    gap: '0.5rem',
    marginBottom: '0.25rem'
  }}>
        <strong>{label}</strong>
        <span style={{
    fontSize: '0.7rem',
    fontWeight: 600,
    textTransform: 'uppercase',
    letterSpacing: '0.04em',
    color: required ? '#6241f5' : '#6b7280'
  }}>
          {required ? 'Required' : 'Optional'}
        </span>
      </div>

      <div>{children}</div>

      {diType || patterns.length > 0 ? <p style={{
    fontSize: '0.85rem',
    color: '#6b7280',
    marginBottom: 0
  }}>
          {diType ? <>
              See the <a href={`/references/${diType}`}>{diType}</a> reference.{' '}
            </> : null}
          {patterns.length > 0 ? <>
              Accepts a <a href={`/documentation/placeholders-and-patterns/patterns#${patterns[0]}`}>pattern</a>.
            </> : null}
        </p> : null}
    </div>;
};

Use this when you are about to write a file and want to avoid overwriting something that is already there. It takes the destination path you give it, checks the chosen filesystem connection, and if a file already exists at that path it applies the conflict resolution strategy you pick to produce a free path instead. For example, `exports/orders.json` becomes `exports/orders-1.json` when the original is taken. When the path is already free, it is returned unchanged. The path it returns is meant to be passed on to a step that writes, copies, or moves the file, so the same conflict handling is also available directly on the Filesystem write, copy, and move transformers.

This documentation describes: [Schema](/schemas/mapper/filesystem-ensure-destination)

## Fields

<FormField property="filesystem" label="Filesystem connection" required diType="filesystem">
  The storage location to check for existing files, such as a local folder, FTP or SFTP server, or cloud bucket. It looks here to decide whether a file is already present at the path. See [filesystem connections](/references/filesystem) for how to set one up.
</FormField>

<FormField property="ensureDestination" label="When the file exists" required diType="filesystem-ensure-destination">
  The strategy that produces an available path when the chosen one is already taken. The available option, "Add an increasing number to the filename", appends a counter that grows until a free name is found (`orders.json`, then `orders-1.json`, then `orders-2.json`, and so on). You control the naming pattern, the number format, the starting number, and whether a number is always added even when the path is already free. See [file actions](/references/filesystem-ensure-destination) for the strategy and its settings.
</FormField>

## Sample data

This feature does not transform a value on its own. It looks at the live filesystem to decide whether a path is already in use, then hands back a safe path, so there is no fixed before/after to show: the same input can return a different result depending on what files already exist. Below is a typical configuration and how it behaves.

| Field                 | Value                                                                     |
| --------------------- | ------------------------------------------------------------------------- |
| Filesystem connection | A connection where `exports/orders.json` already exists                   |
| When the file exists  | Add an increasing number to the filename (default pattern, starting at 0) |

With this configuration, feeding in the path `exports/orders.json` returns `exports/orders-1.json`, because the original name is already taken. If `exports/orders.json` does not exist yet, the same path is returned untouched.

```json Configuration theme={null}
{
  "prototype": "filesystem-ensure-destination",
  "parameters": {
    "filesystem": { "prototype": "<your-filesystem-connection>", "parameters": {} },
    "ensureDestination": {
      "prototype": "increase-counter",
      "parameters": {
        "template": "{dirname}/{filename}-{counter}.{extension}",
        "format": "%d",
        "start": 0,
        "alwaysAddCounter": false
      }
    }
  }
}
```
