---
sidebar:
  hidden: true
title: roboto.domain.files.file_system
---
## Module Contents

### FileSystem

```python
class roboto.domain.files.file_system.FileSystem(
    association: roboto.association.Association,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    file_service: Optional[roboto.storage.FileService] = None,
    org_id: Optional[str] = None,
)
```

`from roboto import FileSystem`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L45-L730)

The files and directories of one dataset, device, device type, or organization, with the operations on them.

That dataset, device, device type, or organization is the file system's `association`. Get a `FileSystem` from [`files`](/docs/reference/python-sdk/roboto/domain/datasets/dataset#roboto.domain.datasets.dataset.Dataset.files) for a dataset's files, [`configurations`](/docs/reference/python-sdk/roboto/domain/devices/device#roboto.domain.devices.device.Device.configurations) for a device's configurations, `device_type.configurations` for a device type's configurations, or [`assets`](/docs/reference/python-sdk/roboto/domain/orgs/org#roboto.domain.orgs.org.Org.assets) for an organization's assets. Uploads and downloads act in the organization that owns the files, so a caller who belongs to several organizations need not name one.

Every path a method takes or returns is relative to the root of the association's files. Each association has its own tree, so one path names different files in two associations.

**Parameters**

- **association** (`roboto.association.Association`)
- **roboto_client** (`Optional[roboto.http.RobotoClient]`)
- **file_service** (`Optional[roboto.storage.FileService]`)
- **org_id** (`Optional[str]`)

**Properties**

- **FileSystem.association** (`roboto.association.Association`): Dataset, device, device type, or organization whose files this object works on.

#### FileSystem.create_directory()

```python
def create_directory(
    name: str,
    error_if_exists: bool = False,
    create_intermediate_dirs: bool = False,
    parent_path: Optional[pathlib.Path] = None,
    origination: Optional[str] = None,
) -> roboto.domain.files.record.DirectoryRecord
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L84-L144)

Create a directory among the association's files.

**Parameters**

- **name** (`str`): Name of the directory, unique within its parent directory.
- **error_if_exists** (`bool`): Whether to raise `RobotoConflictException` when the directory already exists. When `False`, the existing directory is returned.
- **create_intermediate_dirs** (`bool`): Whether to create the directories along `parent_path` that do not exist. When `False`, every directory along it must already exist.
- **parent_path** (`Optional[pathlib.Path]`): Path of the directory to create this one in. `None` creates it at the root.
- **origination** (`Optional[str]`): What created the directory, recorded on it. `None` records the value of the `ROBOTO_ENV` environment variable when it is set, and `roboto <SDK version>` otherwise.

**Returns**

- `roboto.domain.files.record.DirectoryRecord`: Record of the created directory, or of the existing one.

**Raises**

- [`RobotoConflictException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoConflictException): The directory already exists and `error_if_exists` is `True`.
- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): The name is invalid, or a directory along `parent_path` does not exist and `create_intermediate_dirs` is `False`.

**Usage**

Create a directory at the root of a device's configurations:

```python
import pathlib
from roboto.domain import devices
device = devices.Device.from_id("rover-01")
directory = device.configurations.create_directory("calib")
print(directory.relative_path)
# calib
```

Create a nested directory, with the directories along its parent path:

```python
directory = device.configurations.create_directory(
    name="final",
    parent_path=pathlib.Path("path/to/deep"),
    create_intermediate_dirs=True,
)
print(directory.relative_path)
# path/to/deep/final
```

#### FileSystem.create_link()

```python
def create_link(
    target: Union[roboto.domain.files.file.File, str],
    relative_path: str,
) -> roboto.domain.files.file.File
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L146-L187)

Put a link to another file at `relative_path` among the association's files.

Links can be created in a device's or a device type's configurations and in an organization's assets, but not in a dataset's files. A link lets one file appear in many devices' configurations without being copied.

A link pins one version of its target: passing a [`File`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File) pins that file's version, and passing a file ID pins the target's current version. Later versions of the target do not move the link; create the link again at the same path to point it at the new version, which adds a version to the link unless it already pins that target version. Missing parent directories are created. Downloading the link, or asking it for a signed URL, fetches the pinned version of the target. While the link exists, uploading a file to its path raises `RobotoConflictException`.

**Parameters**

- **target** (`Union[roboto.domain.files.file.File, str]`): File to link to, or its ID. It must be a file in the same organization, not a link or a directory.
- **relative_path** (`str`): Path of the link.

**Returns**

- `roboto.domain.files.file.File`: The link, whose [`is_link`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.is_link) is `True`.

**Raises**

- [`RobotoConflictException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoConflictException): A file or a directory already occupies `relative_path`.
- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): The association is a dataset, or the target is a link or a directory, is in another organization, or does not exist at the version to pin.

**Usage**

```python
import pathlib
from roboto.domain import devices, orgs
runbook = orgs.Org.from_id("og_12345").assets.get_file_by_path("runbooks/field_service.pdf")
device = devices.Device.from_id("rover-01")
link = device.configurations.create_link(runbook, "runbooks/field_service.pdf")
link.download(pathlib.Path("/tmp/field_service.pdf"))
```

#### FileSystem.delete_directories()

```python
def delete_directories(directory_paths: list[str]) -> None
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L189-L210)

Delete directories from the association's files, with every file and directory beneath them.

The directories stop appearing in listings when this returns. The files and directories beneath them are removed in the background, so they can still appear for a short while. Deleting a directory that no longer exists succeeds and changes nothing, and a path that names a file deletes that file. A link beneath a deleted directory is deleted, but the file it points at is kept unless it is beneath a deleted directory too. Links elsewhere that point at deleted files stop working. On a device's configurations, only the device's own directories are deleted, never its device type's.

**Parameters**

- **directory_paths** (`list[str]`): Paths of the directories to delete.

**Returns**

- `None`

**Usage**

```python
from roboto.domain import devices
device = devices.Device.from_id("rover-01")
device.configurations.delete_directories(["calib/old", "scratch"])
```

#### FileSystem.delete_files()

```python
def delete_files(
    include_patterns: Optional[list[str]] = None,
    exclude_patterns: Optional[list[str]] = None,
) -> None
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L212-L241)

Delete the association's files that match the given patterns.

Deletes the matching files one request per file, through [`delete()`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.delete), whose failures also apply. When one request fails, the files deleted before it stay deleted. A matching link is deleted; the file it points at is not. On a device's configurations, only the device's own files are deleted; delete its device type's through `device_type.configurations`.

**Parameters**

- **include_patterns** (`Optional[list[str]]`): Gitignore-style patterns for the files to delete. `None` or an empty list selects every file.
- **exclude_patterns** (`Optional[list[str]]`): Gitignore-style patterns for files to keep. Takes precedence over `include_patterns`. `None` or an empty list keeps none.

**Returns**

- `None`

> **Note**
>
> Patterns follow the gitignore format described at [https://git-scm.com/docs/gitignore](https://git-scm.com/docs/gitignore).

**Usage**

Delete every PNG file in an organization's assets except those under a `back_camera` directory:

```python
from roboto.domain import orgs
org = orgs.Org.from_id("og_12345")
org.assets.delete_files(include_patterns=["**/*.png"], exclude_patterns=["**/back_camera/**"])
```

#### FileSystem.download_files()

```python
def download_files(
    out_path: pathlib.Path,
    include_patterns: Optional[list[str]] = None,
    exclude_patterns: Optional[list[str]] = None,
    print_progress: bool = True,
    *,
    include_inherited: bool = False,
) -> list[tuple[roboto.domain.files.record.FileRecord, pathlib.Path]]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L243-L332)

Download the association's files that match the given patterns to a local directory.

Each file is saved at its path under `out_path`. A link is saved at its own path, with the contents of the file version it pins.

**Parameters**

- **out_path** (`pathlib.Path`): Local directory to download into. Created, with any missing parents, if it does not exist.
- **include_patterns** (`Optional[list[str]]`): Gitignore-style patterns for the files to download. `None` or an empty list selects every file.
- **exclude_patterns** (`Optional[list[str]]`): Gitignore-style patterns for files to skip. Takes precedence over `include_patterns`. `None` or an empty list skips none.
- **print_progress** (`bool`): Whether to show a progress bar during the download.
- **include_inherited** (`bool`): Whether, for a device's configurations, to also download its device type's, selected as `list_files` selects them.

**Returns**

- `list[tuple[roboto.domain.files.record.FileRecord, pathlib.Path]]`: One `(record, local_path)` pair per downloaded file.

**Raises**

- [`RobotoIllegalArgumentException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoIllegalArgumentException): A selected file's path resolves outside `out_path`. Nothing is downloaded.
- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): `include_inherited` is `True` for anything but a device's configurations.
- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): A selected link pins a file version that no longer exists. Nothing is downloaded.

> **Note**
>
> Patterns follow the gitignore format described at [https://git-scm.com/docs/gitignore](https://git-scm.com/docs/gitignore).

**Usage**

Download a device's calibration files:

```python
import pathlib
from roboto.domain import devices
device = devices.Device.from_id("rover-01")
downloaded = device.configurations.download_files(
    pathlib.Path("/tmp/rover-01"), include_patterns=["calib/**"]
)
print(f"Downloaded {len(downloaded)} files")
```

#### FileSystem.get_file_by_path()

```python
def get_file_by_path(
    relative_path: Union[str, pathlib.Path],
    version_id: Optional[int] = None,
) -> roboto.domain.files.file.File
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L334-L369)

Fetch the association's file at a path.

On a device's configurations, only the device's own files are looked up. A file the device inherits from its device type is not found here; look it up through `device_type.configurations`.

**Parameters**

- **relative_path** (`Union[str, pathlib.Path]`): Path of the file.
- **version_id** (`Optional[int]`): Version of the file to fetch. `None` fetches the latest version.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): The association has no file at this path.

**Returns**

- `roboto.domain.files.file.File`

**Usage**

Fetch a device's manifest:

```python
from roboto.domain import devices
device = devices.Device.from_id("rover-01")
file = device.configurations.get_file_by_path("manifest.json")
```

Fetch the manifest's first version:

```python
old_file = device.configurations.get_file_by_path("manifest.json", version_id=1)
print(old_file.version)
# 1
```

#### FileSystem.list_directories()

```python
def list_directories() -> collections.abc.Generator[roboto.domain.files.record.DirectoryRecord, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L371-L393)

Yield every directory among the association's files, at any depth.

**Usage**

```python
from roboto.domain import devices
device = devices.Device.from_id("rover-01")
for directory in device.configurations.list_directories():
    print(directory.relative_path)
```

**Returns**

- `collections.abc.Generator[roboto.domain.files.record.DirectoryRecord, None, None]`

#### FileSystem.list_files()

```python
def list_files(
    include_patterns: Optional[list[str]] = None,
    exclude_patterns: Optional[list[str]] = None,
    *,
    include_inherited: bool = False,
) -> collections.abc.Generator[roboto.domain.files.file.File, None, None]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L395-L460)

List the association's files that match the given patterns.

Links are listed alongside files; [`is_link`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.is_link) tells them apart.

**Parameters**

- **include_patterns** (`Optional[list[str]]`): Gitignore-style patterns for the files to list. `None` or an empty list selects every file.
- **exclude_patterns** (`Optional[list[str]]`): Gitignore-style patterns for files to leave out. Takes precedence over `include_patterns`. `None` or an empty list leaves out none.
- **include_inherited** (`bool`): Whether, for a device's configurations, to also list its device type's. Where the device and its type both have a file at the same path, only the device's is listed. `file.association.is_device_type` tells which files came from the type.

**Yields**

- Each matching [`File`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File), fetched a page at a time as the generator advances.

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): `include_inherited` is `True` for anything but a device's configurations. It surfaces on the first iteration.

**Returns**

- `collections.abc.Generator[roboto.domain.files.file.File, None, None]`

> **Note**
>
> Patterns follow the gitignore format described at [https://git-scm.com/docs/gitignore](https://git-scm.com/docs/gitignore). A file appears here shortly after its upload completes, not at once.
>
> Only this method and `download_files` include a device type's configurations. `get_file_by_path`, `rename_file`, `delete_files` and `delete_directories` act on the device's own configurations only, and [`delete()`](/docs/reference/python-sdk/roboto/domain/files/file#roboto.domain.files.file.File.delete) on a file from the type deletes it from the type, for every device of that type.

**Usage**

List every file in a device's configurations:

```python
from roboto.domain import devices
device = devices.Device.from_id("rover-01")
for file in device.configurations.list_files():
    print(file.relative_path)
```

List the calibration files, except backups:

```python
for file in device.configurations.list_files(
    include_patterns=["calib/**"], exclude_patterns=["**/*.bak"]
):
    print(file.relative_path)
```

#### FileSystem.rename_directory()

```python
def rename_directory(
    old_path: str,
    new_path: str,
) -> roboto.domain.files.record.DirectoryRecord
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L462-L493)

Rename or move a directory among the association's files, with everything beneath it.

The last component of `new_path` becomes the directory's name, and the directory at the rest of `new_path` becomes its parent.

**Parameters**

- **old_path** (`str`): Current path of the directory, such as `"logs/session1"`.
- **new_path** (`str`): Path to move the directory to, such as `"session1"` to move it up one level.

**Returns**

- `roboto.domain.files.record.DirectoryRecord`: Record of the moved directory.

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): `new_path` is empty or the same as `old_path`, no directory exists at its parent path, that parent is the directory itself or beneath it, or the name is taken there.
- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): No directory exists at `old_path`.

**Usage**

```python
from roboto.domain import devices
device = devices.Device.from_id("rover-01")
device.configurations.rename_directory("calib/front", "front_calib")
```

#### FileSystem.rename_file()

```python
def rename_file(file_id: str, new_path: str) -> roboto.domain.files.record.FileRecord
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L495-L528)

Rename or move one of the association's files.

The file keeps its ID, topics, and events. The rename adds a version of the file at `new_path`.

**Parameters**

- **file_id** (`str`): ID of the file to rename or move.
- **new_path** (`str`): Path to move the file to, such as `"file.bag"` to move it to the root or `"other_dir/file.bag"` to move it into an existing directory.

**Returns**

- `roboto.domain.files.record.FileRecord`: Record of the file's new version.

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): No directory exists at `new_path`'s parent path, the name is taken there, or the file belongs to another association.
- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): No file has this ID.

**Usage**

```python
from roboto.domain import devices
device = devices.Device.from_id("rover-01")
record = device.configurations.rename_file("fl_12345", "manifest.json")
record.relative_path
# 'manifest.json'
```

#### FileSystem.upload_directory()

```python
def upload_directory(
    directory_path: pathlib.Path,
    include_patterns: Optional[list[str]] = None,
    exclude_patterns: Optional[list[str]] = None,
    delete_after_upload: bool = False,
    max_batch_size: int = MAX_FILES_PER_MANIFEST,
    print_progress: bool = True,
    device_id: Optional[str] = None,
) -> None
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L530-L584)

Upload every file under a local directory, at any depth, to the association's files.

Each file is uploaded to its path relative to `directory_path`, so the association's files mirror the local layout.

**Parameters**

- **directory_path** (`pathlib.Path`): Local directory whose files to upload.
- **include_patterns** (`Optional[list[str]]`): Gitignore-style patterns for the files to upload. `None` uploads every file; an empty list uploads none.
- **exclude_patterns** (`Optional[list[str]]`): Gitignore-style patterns for files to skip. Takes precedence over `include_patterns`.
- **delete_after_upload** (`bool`): Whether to delete each uploaded local file once every upload has succeeded. Directories are kept.
- **max_batch_size** (`int`): Maximum number of files per upload batch. Each batch finishes uploading before the next starts.
- **print_progress** (`bool`): Whether to show a progress bar during the upload.
- **device_id** (`Optional[str]`): ID of the device that produced the files' data.

**Returns**

- `None`

> **Note**
>
> Patterns follow the gitignore format described at [https://git-scm.com/docs/gitignore#\_pattern_format](https://git-scm.com/docs/gitignore#_pattern_format), but each is matched against a file's name only, not its path under `directory_path`. A pattern naming a directory, such as `"__pycache__/"`, matches no file.

**Usage**

Upload a calibration directory to a device's configurations, skipping log files:

```python
import pathlib
from roboto.domain import devices
device = devices.Device.from_id("rover-01")
device.configurations.upload_directory(
    pathlib.Path("/path/to/calibration"),
    exclude_patterns=["*.log"],
)
```

#### FileSystem.upload_file()

```python
def upload_file(
    file_path: pathlib.Path,
    file_destination_path: Optional[str] = None,
    print_progress: bool = True,
    device_id: Optional[str] = None,
) -> roboto.domain.files.file.File
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L586-L635)

Upload one local file to the association's files.

**Parameters**

- **file_path** (`pathlib.Path`): Local file to upload.
- **file_destination_path** (`Optional[str]`): Path to upload the file to. `None` uploads it to the root under its own name.
- **print_progress** (`bool`): Whether to show a progress bar during the upload.
- **device_id** (`Optional[str]`): ID of the device that produced the file's data.

**Returns**

- `roboto.domain.files.file.File`: The uploaded file. Its record is fetched from Roboto the first time it is read.

**Raises**

- [`RobotoInternalException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInternalException): The upload finished without reporting the new file's ID.

**Usage**

```python
import pathlib
from roboto.domain import devices
device = devices.Device.from_id("rover-01")
device.configurations.upload_file(pathlib.Path("/path/to/manifest.json"))
```

#### FileSystem.upload_files()

```python
def upload_files(
    files: collections.abc.Iterable[pathlib.Path],
    file_destination_paths: collections.abc.Mapping[pathlib.Path, str] = {},
    max_batch_size: int = MAX_FILES_PER_MANIFEST,
    print_progress: bool = True,
    device_id: Optional[str] = None,
) -> dict[pathlib.Path, str]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L637-L690)

Upload several local files to the association's files.

**Parameters**

- **files** (`collections.abc.Iterable[pathlib.Path]`): Local files to upload, as a list or another collection that can be iterated more than once.
- **file_destination_paths** (`collections.abc.Mapping[pathlib.Path, str]`): Path to upload each local file to, keyed by local path. A file not in the mapping is uploaded to the root under its own name.
- **max_batch_size** (`int`): Maximum number of files per upload batch. Each batch finishes uploading before the next starts.
- **print_progress** (`bool`): Whether to show a progress bar during the upload.
- **device_id** (`Optional[str]`): ID of the device that produced the files' data.

**Returns**

- `dict[pathlib.Path, str]`: ID of the file each local path was uploaded as, keyed by local path.

**Raises**

- `ValueError`: Two local files would be uploaded to the same path. Raised before any upload starts.

**Usage**

```python
import pathlib
from roboto.domain import devices
device = devices.Device.from_id("rover-01")
file_ids = device.configurations.upload_files(
    [pathlib.Path("/path/to/front_cam.yaml")],
    file_destination_paths={pathlib.Path("/path/to/front_cam.yaml"): "calib/front_cam.yaml"},
)
print(file_ids[pathlib.Path("/path/to/front_cam.yaml")])
```

### MAX_FILES_PER_MANIFEST

```python
roboto.domain.files.file_system.MAX_FILES_PER_MANIFEST = 500
```

`from roboto.domain.files.file_system import MAX_FILES_PER_MANIFEST`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/domain/files/file_system.py#L41-L41)

Default `max_batch_size` of the upload methods: the most files uploaded in one batch.
