Skip to main content
The Filesystem API provides methods for interacting with the file system, including reading and writing files, checking file existence, and working with directories.

File Operations

readFile

Read entire file contents as UTF-8 string.
string
required
File path (absolute or relative to cwd)
Promise<string>
File contents as UTF-8 string
Throws if file doesn’t exist, isn’t readable, or isn’t valid UTF-8. For binary files, this will fail. For large files, consider memory usage.
Example:

writeFile

Write string content to a NEW file (fails if file exists).
string
required
Destination path (absolute or relative to cwd)
string
required
UTF-8 string to write
Creates a new file with the given content. Fails if the file already exists to prevent plugins from accidentally overwriting user data.
Example:

fileExists

Check if a path exists (file, directory, or symlink).
string
required
Path to check (absolute or relative to cwd)
boolean
true if path exists, false otherwise
Does not follow symlinks; returns true for broken symlinks. Use fileStat for more detailed information.
Example:

fileStat

Get metadata about a file or directory.
string
required
Path to stat (absolute or relative to cwd)
FileStat
File metadata object
FileStat Type:
Follows symlinks. Returns exists=false for non-existent paths rather than throwing. Size is in bytes; directories may report 0.
Example:

Directory Operations

readDir

List directory contents.
string
required
Directory path (absolute or relative to cwd)
DirEntry[]
Array of directory entries
DirEntry Type:
Returns unsorted entries with type info. Entry names are relative to the directory (use pathJoin to construct full paths). Throws on permission errors or if path is not a directory.
Example:

Path Operations

pathJoin

Join path segments using the OS path separator.
string[]
required
Path segments to join
string
Joined path string
Handles empty segments and normalizes separators. If a segment is absolute, previous segments are discarded.
Example:

pathDirname

Get the parent directory of a path.
string
required
File or directory path
string
Parent directory path, or empty string for root paths
Does not resolve symlinks or check existence.
Example:

pathBasename

Get the final component of a path.
string
required
File or directory path
string
Final path component, or empty string for root paths
Does not strip file extension; use pathExtname for that.
Example:

pathExtname

Get the file extension including the dot.
string
required
File path
string
File extension with dot, or empty string if no extension
Only returns the last extension for files like “archive.tar.gz” (returns “.gz”).
Example:

pathIsAbsolute

Check if a path is absolute.
string
required
Path to check
boolean
true if path is absolute, false otherwise
On Unix: starts with ”/”. On Windows: starts with drive letter or UNC path.
Example:

Environment Operations

getCwd

Get the editor’s current working directory.
string
Absolute path to the editor’s working directory set at startup
Use as base for resolving relative paths.
Example:

getEnv

Get an environment variable.
string
required
Name of environment variable
string
Environment variable value, or empty string if not set
Example:

Examples

Read config file

List files in directory

Find files recursively