Skip to content

DataAdapter

Official

Work directly with files and folders inside a vault. If possible prefer using the obsidian#Vault API over this.

Import:

import type { DataAdapter } from 'obsidian';

Signature:

export interface DataAdapter

Methods

MethodReturnsDescription
append(normalizedPath, data, options?)Promise<void>Add text to the end of a plaintext file.
appendBinary(normalizedPath, data, options?)Promise<void>Add data to the end of a binary file.
copy(normalizedPath, normalizedNewPath)Promise<void>Create a copy of a file. This will fail if there is already a file at normalizedNewPath.
exists(normalizedPath, sensitive?)Promise<boolean>Check if something exists at the given path. For a faster way to synchronously check if a note or attachment is in the vault, use Vault.getAbstractFileByPath.
getName()stringGets the name of the vault.
getResourcePath(normalizedPath)stringReturns a URI for the browser engine to use, for example to embed an image.
list(normalizedPath)Promise<ListedFiles>Retrieve a list of all files and folders inside the given folder, non-recursive.
mkdir(normalizedPath)Promise<void>Create a directory.
process(normalizedPath, fn, options?)Promise<string>Atomically read, modify, and save the contents of a plaintext file.
read(normalizedPath)Promise<string>Read the contents of a file.
readBinary(normalizedPath)Promise<ArrayBuffer>Read the contents of a binary file.
remove(normalizedPath)Promise<void>Delete a file.
rename(normalizedPath, normalizedNewPath)Promise<void>Rename a file or folder.
rmdir(normalizedPath, recursive)Promise<void>Remove a directory.
stat(normalizedPath)Promise<Stat | null>Retrieve metadata about the given file/folder.
trashLocal(normalizedPath)Promise<void>Move to local trash. Files will be moved into the .trash folder at the root of the vault.
trashSystem(normalizedPath)Promise<boolean>Try moving to system trash.
write(normalizedPath, data, options?)Promise<void>Write to a plaintext file. If the file exists its content will be overwritten, otherwise the file will be created.
writeBinary(normalizedPath, data, options?)Promise<void>Write to a binary file. If the file exists its content will be overwritten, otherwise the file will be created.

Links to this page: