Skip to main content
The fs namespace provides filesystem operations that work with both local and remote (VFS) files.

File Access

fs.access()

Create a file access builder for opening files with specific permissions.
Access
Access builder object

Access Methods

  • :append(bool) - Open for appending
  • :create(bool) - Create file if it doesn’t exist
  • :create_new(bool) - Create new file, fail if exists
  • :read(bool) - Open for reading
  • :write(bool) - Open for writing
  • :truncate(bool) - Truncate file on open
  • :open(url) - Open the file and return file descriptor

File Operations

fs.copy(from, to)

Copy a file from one location to another.
Url
required
Source file URL
Url
required
Destination file URL
number|nil, Error
Number of bytes copied, or (nil, error)

fs.rename(from, to)

Rename/move a file or directory.
Url
required
Source URL
Url
required
Destination URL
bool, Error|nil
Success boolean, or (false, error)

fs.write(url, data)

Write data to a file.
Url
required
File URL
string
required
Data to write
bool, Error|nil
Success boolean, or (false, error)

Directory Operations

fs.create(type, url)

Create a directory.
string
required
Either "dir" or "dir_all" (creates parent directories)
Url
required
Directory URL
bool, Error|nil
Success boolean, or (false, error)

fs.remove(type, url)

Remove a file or directory.
string
required
One of: "file", "dir", "dir_all" (recursive), "dir_clean" (only if empty)
Url
required
File/directory URL
bool, Error|nil
Success boolean, or (false, error)

fs.read_dir(dir, options)

Read directory contents.
Url
required
Directory URL
table
Read options
string
Glob pattern to filter files
number
Maximum number of files to read (default: unlimited)
bool
Resolve symlinks and get full metadata (default: false)
File[]|nil, Error
List of files, or (nil, error)

File Metadata

fs.cha(url, follow?)

Get file characteristics (metadata).
Url
required
File URL
bool
Follow symlinks (default: false)
Cha|nil, Error
File characteristics, or (nil, error)

Cha Fields

  • len (number) - File size in bytes
  • is_dir (bool) - Is directory
  • is_hidden (bool) - Is hidden file
  • is_link (bool) - Is symbolic link
  • is_orphan (bool) - Is orphan symlink
  • is_block (bool) - Is block device
  • is_char (bool) - Is character device
  • is_fifo (bool) - Is FIFO
  • is_sock (bool) - Is socket
  • is_exec (bool) - Is executable
  • is_sticky (bool) - Has sticky bit
  • modified (number) - Last modified time (timestamp)
  • accessed (number) - Last accessed time (timestamp)
  • created (number) - Created time (timestamp)
  • permissions (string) - Unix permissions string (e.g., “rwxr-xr-x”)

fs.calc_size(url)

Calculate total size of a directory (async iterator).
Url
required
Directory URL
SizeCalculator|nil, Error
Size calculator iterator, or (nil, error)

Utilities

fs.unique(type, url)

Create a unique file or directory name (handles naming conflicts).
string
required
Either "file" or "dir"
Url
required
Desired URL (may be modified to be unique)
Url|nil, Error
Unique URL, or (nil, error)
This replaces the deprecated fs.unique_name() to fix TOCTOU race conditions. See #3677.

fs.cwd()

Get the current working directory.
Url|nil, Error
Current directory URL, or (nil, error)

fs.expand_url(value)

Expand ~ and environment variables in a URL/path string.
string|Url
required
URL string or Url object
Url
Expanded URL

fs.partitions()

Get list of mounted partitions.
table[]
List of partition info tables
Each partition table contains:
  • src (string) - Device path
  • dist (string) - Mount point
  • label (string) - Volume label
  • fstype (string) - Filesystem type
  • external (bool) - Is external drive
  • removable (bool) - Is removable media

File Operations Helper

fs.op(name, options)

Low-level file operation helper (internal use).
string
required
Operation name: "part", "done", "size"
table
required
Operation-specific options
This is used internally by Yazi for progress tracking of file operations.