# Directory

## *class* <mark style="color:purple;">Directory</mark>

Any table or query result on Redivis that contains file ids can be read as a directory, where the file names are parsed according to any `/` separators, and a directory tree is created.&#x20;

This virtual directory can then be used to navigate, download, and even mount a given file tree.

## Constructors

<table data-header-hidden><thead><tr><th width="319">Method</th><th>Description</th></tr></thead><tbody><tr><td><a href="/pages/ko984apgZa0RNDgYCAAL"><strong><code>Directory.get</code></strong></a>(path)</td><td>Returns a subdirectory within a directory.</td></tr><tr><td><a href="/pages/sdxEF4G9mtvQZsjYeS7f"><strong><code>Query.to_directory</code></strong></a>(name)</td><td>Load query results that contain a <code>file_id</code> variable as a directory.</td></tr><tr><td><a href="/pages/sdxEF4G9mtvQZsjYeS7f"><strong><code>Table.to_directory</code></strong></a>(name)</td><td>Load any table contains a <code>file_id</code> variable as a directory.</td></tr></tbody></table>

## Examples

{% tabs %}
{% tab title="Basics" %}

```python
import redivis

dir = redivis.table("table_ref").to_directory()
print(dir.list()) # list files + directories within this directory
all_files = dir.list(mode="files", recursive=True)

file = dir.get("path/to/file.txt") # Will return None if doesn't exist
subdir = dir.get("path/to/subdir")
```

{% endtab %}

{% tab title="Mount & Download files" %}

```python
import redivis

dir = redivis.table("table_ref").to_directory()

# Download all files to the provided path
dir.download("/download/path")

# dir.mount() behaves the same as dir.download() was called (all files appear on disk)
# However, this doesn't actually download the files until they're needed, 
#    and as such is much faster, particularly when all files may not need to be read.
dir.mount("/download/path")
```

{% endtab %}
{% endtabs %}

## Attributes

| **`path`**  | <p>The path of this directory (a <code>pathlib.Path</code>) relative to the root directory in the current tree. <br><br>The path of the top-level directory (that is, any directory returned from table / query <code>.to\_directory()</code> ) will always be <code>"/"</code></p> |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`query`** | A reference to the [Query](/api/client-libraries/redivis-python/reference/query.md) that constructed this directory. Will be `None` if the directory is derived from a table.                                                                                                       |
| **`table`** | A reference to the [Table](/api/client-libraries/redivis-python/reference/table.md) that constructed this directory. Will be `None` if the directory is derived from a query.                                                                                                       |

## Methods

<table data-header-hidden><thead><tr><th width="441"></th><th></th></tr></thead><tbody><tr><td><a href="/pages/p2MvkTVyyTQIAKBhx28t"><strong>Directory.download</strong></a>([path, *, overwrite, ...])</td><td>Downloads files in the directory to the specified path.</td></tr><tr><td><a href="/pages/ko984apgZa0RNDgYCAAL"><strong>Directory.get</strong></a>(path)</td><td>Get a file or directory relative to this directory</td></tr><tr><td><a href="/pages/M71WneRMzhKsiHOgQPjN"><strong>Directory.list</strong></a>([max_results, *, mode, recursive])</td><td>List the contents of a directory</td></tr><tr><td><a href="/pages/QVzFAcFF2ij8MGHEsrES"><strong>Directory.mount</strong></a>([path, *, foreground])</td><td>Mount the directory as a volume at the provided path, allowing files to be lazily loaded as they're accessed.</td></tr><tr><td><a href="/pages/20A2lsdqUDL6q0Vb95Nx"><strong>Directory.unmount</strong></a>([path, *, foreground])</td><td>Unmounts a previously mounted directory.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.redivis.com/api/client-libraries/redivis-python/reference/directory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
