Skip to main content

expo-file-system

Version: 55.0.6 Provides access to the local file system on the device. Read, write, delete files and directories, download files, and manage app storage with a modern, Promise-based API.

Installation

Usage

Modern API (v55+)

Paths

Access system directories:
Directory
Cache directory – files can be deleted by the system
Directory
Document directory – persistent storage safe from system deletion
Directory
Bundle directory – contains assets bundled with the app (read-only)

File Class

Represents a file on the filesystem:

Methods

() => Promise<void>
Creates the file if it doesn’t exist
(content: string | Uint8Array) => Promise<void>
Writes content to the file
() => Promise<string>
Reads file content as text
() => Promise<Uint8Array>
Reads file content as bytes
() => Promise<void>
Deletes the file
() => Promise<boolean>
Checks if the file exists
(destination: File | Directory) => Promise<File>
Copies the file to a new location
(destination: File | Directory) => Promise<File>
Moves the file to a new location

Properties

string
The file URI (e.g., file:///path/to/file.txt)
string
File name with extension
string
File extension (e.g., .txt, .json)
Directory
The directory containing this file
number
File size in bytes

Directory Class

Represents a directory on the filesystem:

Methods

() => Promise<void>
Creates the directory if it doesn’t exist
() => Promise<void>
Deletes the directory and its contents
() => Promise<boolean>
Checks if the directory exists
() => (File | Directory)[]
Lists contents of the directory
(name: string, mimeType?: string) => File
Creates a new file in this directory
(name: string) => Directory
Creates a new subdirectory

Properties

string
The directory URI
string
Directory name
Directory
The parent directory

Download Files

static
Downloads a file from a URL

Examples

Read and Write Text Files

Work with JSON

Create Directory Structure

List Directory Contents

Download and Save File

Copy and Move Files

Check File Existence

Binary Data Handling

Stream Large Files

Storage Info

Legacy API

For backwards compatibility, the legacy API is still available:
Use the modern API (File, Directory, Paths) for new projects. The legacy API is maintained for compatibility only.

TypeScript

Platform Support

On web, file system access is limited to browser storage. Not all features are available.

Best Practices

  1. Use Document Directory: Store user data in Paths.document for persistence
  2. Use Cache Directory: Store temporary data in Paths.cache
  3. Check Existence: Always check if files exist before reading
  4. Handle Errors: Wrap file operations in try/catch blocks
  5. Clean Up: Delete unnecessary files from cache regularly

Resources