---
title: to_file function
description: The to\_file function in Databricks SQL and Databricks Runtime returns a FILE value that references the file at a given path. Raises an error if the file doesn't exist or is inaccessible.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/to_file
---

# `to_file` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 18 LTS and above

> [!NOTE]
> **Beta**
>
> This feature is in [Beta](https://docs.databricks.com/aws/en/release-notes/release-types.md).

Returns a `FILE` value that references the file at `path`.

## Syntax

```
to_file(path)
```

## Arguments

* `path`: A `STRING` expression specifying the path to a file. For example, a path in a Unity Catalog volume.

## Returns

A `FILE` value that references the file at `path`.

To gather file metadata, Databricks makes a remote call to the file's storage location. If the file doesn't exist or is inaccessible, Databricks raises an error. To return `NULL` instead, use [`try_to_file` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/try_to_file.md).

## Common error conditions

* `TO_FILE_ERROR.FILE_NOT_EXISTS`
* `TO_FILE_AUTHORIZATION_ERROR.READ_UNAUTHORIZED`
* `TO_FILE_ILLEGAL_USAGE.NO_PATH_PROVIDED`

For more information, see [Error conditions in Databricks](https://docs.databricks.com/aws/en/error-messages/error-classes.md).

## Examples

To create a `FILE` reference from a path in a volume:

```sql
SELECT to_file('/Volumes/my_catalog/my_schema/my_volume/report.pdf');
```

If the path doesn't exist or the user lacks read permission, `to_file` raises an error:

```sql
SELECT to_file('/Volumes/my_catalog/my_schema/my_volume/ghost.csv');
```

```text
Error: TO_FILE_ERROR.FILE_NOT_EXISTS
```

## Related functions

* [`try_to_file` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/try_to_file.md)
* [`create_file` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/create_file.md)
* [`copy_file` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/copy_file.md)
* [`try_copy_file` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/try_copy_file.md)
* [`list_files` table-valued function](https://docs.databricks.com/aws/en/sql/language-manual/functions/list_files.md)
* [`read_files` table-valued function](https://docs.databricks.com/aws/en/sql/language-manual/functions/read_files.md)
* [`ai_parse_document` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/ai_parse_document.md)
* [`FILE` type](https://docs.databricks.com/aws/en/sql/language-manual/data-types/file-type.md)
