> For the complete documentation index, see [llms.txt](https://docs.redivis.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.redivis.com/api/client-libraries/redivis-js/reference/directory.md).

# Directory

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

A virtual directory of the non-tabular files in a [file index table](https://docs.redivis.com/reference/datasets/files) (or in query results with a `file_id` variable), reflecting the folder structure of the files' paths. Directories can be navigated, listed, and downloaded.

## Constructors

| Method                                                                                                                                         | Description                                                                                                                     |
| ---------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| [**`Table.toDirectory`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/table/table.todirectory.md)(\[options])           | Return the root Directory of a file index table's files.                                                                        |
| [**`Query.toDirectory`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/table/table.todirectory.md)(\[options])           | Return the root Directory of the files referenced by a query's results.                                                         |
| [**`Directory.get`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/directory/directory.get.md)(path)                     | Return a subdirectory (or [File](https://docs.redivis.com/api/client-libraries/redivis-js/reference/file.md)) of a directory.   |
| [**`Directory.list`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/directory/directory.list.md)(\[maxResults, options]) | List the subdirectories and [Files](https://docs.redivis.com/api/client-libraries/redivis-js/reference/file.md) of a directory. |

## Examples

```javascript
const table = redivis.table('demo.example_data_files:yz1s:v1_3.example_file_types:4c10');
const directory = await table.toDirectory();

directory.list(); // The files and directories at the root
directory.list({ mode: 'files', recursive: true }); // Every file

const file = directory.get('path/to/file.txt'); // Returns null if there's no such file
const subdirectory = directory.get('path/to/');

// Download all files to the provided path (Node.js only)
await directory.download('/download/path');
```

## Attributes

| Name           | Description                                                                                                                                                         |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`name`**     | The directory's name (an empty string for the root directory).                                                                                                      |
| **`path`**     | The directory's absolute path, e.g. `/images/2024`. The root directory's path is `/`.                                                                               |
| **`parent`**   | The parent Directory, or `undefined` for the root directory.                                                                                                        |
| **`children`** | A `Map` of the directory's immediate children ([Files](https://docs.redivis.com/api/client-libraries/redivis-js/reference/file.md) and Directories), keyed by name. |
| **`table`**    | The [Table](https://docs.redivis.com/api/client-libraries/redivis-js/reference/table.md) that the files belong to, if any.                                          |
| **`query`**    | The [Query](https://docs.redivis.com/api/client-libraries/redivis-js/reference/query.md) that the files belong to, if any.                                          |

## Methods

| Method                                                                                                                                           | Description                                                                                                                                          |
| ------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| [**`Directory.download`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/directory/directory.download.md)(\[path, options]) | Download all files in the directory, recreating its structure (Node.js only).                                                                        |
| [**`Directory.get`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/directory/directory.get.md)(path)                       | Return the [File](https://docs.redivis.com/api/client-libraries/redivis-js/reference/file.md) or Directory at a path, or `null` if it doesn't exist. |
| [**`Directory.list`**](https://docs.redivis.com/api/client-libraries/redivis-js/reference/directory/directory.list.md)(\[maxResults, options])   | List the directory's files and subdirectories.                                                                                                       |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
