Skip to content

DataAdapter

Defined in: obsidian.d.ts:935

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

Extends

Extended by

Properties

basePath

basePath: string

Defined in: src/obsidian/augmentations/DataAdapter.d.ts:13

Base OS path for the vault (e.g. /home/user/vault, or C:\Users\user\documents\vault)


files

files: DataAdapterFilesRecord

Defined in: src/obsidian/augmentations/DataAdapter.d.ts:17

Mapping of file/folder path to vault entry, includes non-MD files


promise

promise: Promise<unknown>

Defined in: src/obsidian/internals/PromisedQueue.d.ts:3

Inherited from

PromisedQueue.promise

Methods

_exists()

_exists(fullPath, sensitive?): Promise<boolean>

Defined in: src/obsidian/augmentations/DataAdapter.d.ts:32

Check if a file exists.

Parameters

fullPath

string

Full path to the file.

sensitive?

boolean

Whether to check case-sensitive.

Returns

Promise<boolean>

A promise that resolves to true if the file exists, false otherwise.


append()

append(normalizedPath, data, options?): Promise<void>

Defined in: obsidian.d.ts:996

Add text to the end of a plaintext file.

Parameters

normalizedPath

string

path to file, use normalizePath to normalize beforehand.

data

string

the text to append.

options?

DataWriteOptions

(Optional)

Returns

Promise<void>


copy()

copy(normalizedPath, normalizedNewPath): Promise<void>

Defined in: obsidian.d.ts:1060

Create a copy of a file. This will fail if there is already a file at normalizedNewPath.

Parameters

normalizedPath

string

path to file, use normalizePath to normalize beforehand.

normalizedNewPath

string

path to file, use normalizePath to normalize beforehand.

Returns

Promise<void>


exists()

exists(normalizedPath, sensitive?): Promise<boolean>

Defined in: obsidian.d.ts:948

Check if something exists at the given path.

Parameters

normalizedPath

string

path to file/folder, use normalizePath to normalize beforehand.

sensitive?

boolean

Some file systems/operating systems are case-insensitive, set to true to force a case-sensitivity check.

Returns

Promise<boolean>


getFullPath()

getFullPath(path): string

Defined in: src/obsidian/augmentations/DataAdapter.d.ts:39

Get canonical full path of file.

Parameters

path

string

Path to file.

Returns

string

Full path to file.


getFullRealPath()

getFullRealPath(normalizedPath): string

Defined in: src/obsidian/augmentations/DataAdapter.d.ts:46

Get canonical full path of file.

Parameters

normalizedPath

string

Normalized path to file.

Returns

string

String full path to file.


getName()

getName(): string

Defined in: obsidian.d.ts:940

Returns

string


getRealPath()

getRealPath(path): string

Defined in: src/obsidian/augmentations/DataAdapter.d.ts:55

Get normalized path. For vault-relative path, it’s normalized vault-relative path. For absolute path, it’s path as is.

Parameters

path

string

Path to file.

Returns

string

Normalized path.


getResourcePath()

getResourcePath(normalizedPath): string

Defined in: obsidian.d.ts:1011

Returns an URI for the browser engine to use, for example to embed an image.

Parameters

normalizedPath

string

path to file/folder, use normalizePath to normalize beforehand.

Returns

string


list()

list(normalizedPath): Promise<ListedFiles>

Defined in: obsidian.d.ts:960

Retrieve a list of all files and folders inside the given folder, non-recursive.

Parameters

normalizedPath

string

path to folder, use normalizePath to normalize beforehand.

Returns

Promise<ListedFiles>


mkdir()

mkdir(normalizedPath): Promise<void>

Defined in: obsidian.d.ts:1017

Create a directory.

Parameters

normalizedPath

string

path to use for new folder, use normalizePath to normalize beforehand.

Returns

Promise<void>


process()

process(normalizedPath, fn, options?): Promise<string>

Defined in: obsidian.d.ts:1005

Atomically read, modify, and save the contents of a plaintext file.

Parameters

normalizedPath

string

path to file/folder, use normalizePath to normalize beforehand.

fn

(data) => string

a callback function which returns the new content of the file synchronously.

options?

DataWriteOptions

write options.

Returns

Promise<string>

string - the text value of the file that was written.


queue()

queue<T>(fn): Promise<T>

Defined in: src/obsidian/internals/PromisedQueue.d.ts:5

Type Parameters

T

Parameters

fn

() => T | Promise<T>

Returns

Promise<T>

Inherited from

PromisedQueue.queue


read()

read(normalizedPath): Promise<string>

Defined in: obsidian.d.ts:965

Parameters

normalizedPath

string

path to file, use normalizePath to normalize beforehand.

Returns

Promise<string>


readBinary()

readBinary(normalizedPath): Promise<ArrayBuffer>

Defined in: obsidian.d.ts:970

Parameters

normalizedPath

string

path to file, use normalizePath to normalize beforehand.

Returns

Promise<ArrayBuffer>


remove()

remove(normalizedPath): Promise<void>

Defined in: obsidian.d.ts:1044

Delete a file.

Parameters

normalizedPath

string

path to file, use normalizePath to normalize beforehand.

Returns

Promise<void>


rename()

rename(normalizedPath, normalizedNewPath): Promise<void>

Defined in: obsidian.d.ts:1052

Rename a file or folder.

Parameters

normalizedPath

string

current path to file/folder, use normalizePath to normalize beforehand.

normalizedNewPath

string

new path to file/folder, use normalizePath to normalize beforehand.

Returns

Promise<void>


rmdir()

rmdir(normalizedPath, recursive): Promise<void>

Defined in: obsidian.d.ts:1038

Remove a directory.

Parameters

normalizedPath

string

path to folder, use normalizePath to normalize beforehand.

recursive

boolean

If true, delete folders under this folder recursively, if false the folder needs to be empty.

Returns

Promise<void>


stat()

stat(normalizedPath): Promise<null | Stat>

Defined in: obsidian.d.ts:954

Retrieve metadata about the given file/folder.

Parameters

normalizedPath

string

path to file/folder, use normalizePath to normalize beforehand.

Returns

Promise<null | Stat>


trashLocal()

trashLocal(normalizedPath): Promise<void>

Defined in: obsidian.d.ts:1031

Move to local trash. Files will be moved into the .trash folder at the root of the vault.

Parameters

normalizedPath

string

path to file/folder, use normalizePath to normalize beforehand.

Returns

Promise<void>


trashSystem()

trashSystem(normalizedPath): Promise<boolean>

Defined in: obsidian.d.ts:1024

Try moving to system trash.

Parameters

normalizedPath

string

path to file/folder, use normalizePath to normalize beforehand.

Returns

Promise<boolean>

Returns true if succeeded. This can fail due to system trash being disabled.


write()

write(normalizedPath, data, options?): Promise<void>

Defined in: obsidian.d.ts:979

Write to a plaintext file. If the file exists its content will be overwritten, otherwise the file will be created.

Parameters

normalizedPath

string

path to file, use normalizePath to normalize beforehand.

data

string

new file content

options?

DataWriteOptions

(Optional)

Returns

Promise<void>


writeBinary()

writeBinary(normalizedPath, data, options?): Promise<void>

Defined in: obsidian.d.ts:988

Write to a binary file. If the file exists its content will be overwritten, otherwise the file will be created.

Parameters

normalizedPath

string

path to file, use normalizePath to normalize beforehand.

data

ArrayBuffer

the new file content

options?

DataWriteOptions

(Optional)

Returns

Promise<void>