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 bytesis_dir(bool) - Is directoryis_hidden(bool) - Is hidden fileis_link(bool) - Is symbolic linkis_orphan(bool) - Is orphan symlinkis_block(bool) - Is block deviceis_char(bool) - Is character deviceis_fifo(bool) - Is FIFOis_sock(bool) - Is socketis_exec(bool) - Is executableis_sticky(bool) - Has sticky bitmodified(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
src(string) - Device pathdist(string) - Mount pointlabel(string) - Volume labelfstype(string) - Filesystem typeexternal(bool) - Is external driveremovable(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