---
title: try_to_file function
description: The try\_to\_file function in Databricks SQL and Databricks Runtime returns a FILE value that references the file at a given path, or NULL if the file doesn't exist or is inaccessible.
canonical_url: https://docs.databricks.com/gcp/en/sql/language-manual/functions/try_to_file
---

# `try_to_file` function

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

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

Returns a `FILE` value that references the file at `path`, or `NULL` if the file doesn't exist or is inaccessible.

## Syntax

```
try_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`, or `NULL` if the file doesn't exist or is inaccessible.

This function is the error-tolerant version of [`to_file` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/to_file.md). To gather file metadata, Databricks makes a remote call to the file's storage location. If the file doesn't exist or is inaccessible, this function returns `NULL` instead of raising an error.

## Common error conditions

* `TO_FILE_ILLEGAL_USAGE.NO_PATH_PROVIDED`

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

## Examples

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

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

If the path doesn't exist or is inaccessible, `try_to_file` returns `NULL`:

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

```text
NULL
```

## Related functions

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