Vault class
Work with files and folders stored inside a vault.
Signature:
export class Vault extends Events
Extends: Events
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
adapter | DataAdapter | ||
configDir | string | Gets the path to the config folder. This value is typically .obsidian but it could be different. |
Methods
Method | Modifiers | Description |
---|---|---|
append(file, data, options) | Add text to the end of a plaintext file inside the vault. | |
cachedRead(file) | Read the content of a plaintext file stored inside the vault Use this if you only want to display the content to the user. If you want to modify the file content afterward use Vault.read() | |
copy(file, newPath) | Create a copy of a file or folder. | |
create(path, data, options) | Create a new plaintext file inside the vault. | |
createBinary(path, data, options) | Create a new binary file inside the vault. | |
createFolder(path) | Create a new folder inside the vault. | |
delete(file, force) | Deletes the file completely. | |
getAbstractFileByPath(path) | Get a file or folder inside the vault at the given path. To check if the return type is a file, use instanceof TFile . To check if it is a folder, use instanceof TFolder . | |
getAllFolders(includeRoot) | Get all folders in the vault. | |
getAllLoadedFiles() | Get all files and folders in the vault. | |
getFileByPath(path) | Get a file inside the vault at the given path. Returns null if the file does not exist. | |
getFiles() | Get all files in the vault. | |
getFolderByPath(path) | Get a folder inside the vault at the given path. Returns null if the folder does not exist. | |
getMarkdownFiles() | Get all Markdown files in the vault. | |
getName() | Gets the name of the vault. | |
getResourcePath(file) | Returns an URI for the browser engine to use, for example to embed an image. | |
getRoot() | Get the root folder of the current vault. | |
modify(file, data, options) | Modify the contents of a plaintext file. | |
modifyBinary(file, data, options) | Modify the contents of a binary file. | |
off(name, callback) | (Inherited from Events) | |
offref(ref) | (Inherited from Events) | |
on(name: 'create', callback, ctx) | Called when a file is created. This is also called when the vault is first loaded for each existing file If you do not wish to receive create events on vault load, register your event handler inside Workspace.onLayoutReady(). | |
on(name: 'modify', callback, ctx) | Called when a file is modified. | |
on(name: 'delete', callback, ctx) | Called when a file is deleted. | |
on(name: 'rename', callback, ctx) | Called when a file is renamed. | |
process(file, fn, options) | Atomically read, modify, and save the contents of a note. | |
read(file) | Read a plaintext file that is stored inside the vault, directly from disk. Use this if you intend to modify the file content afterwards. Use Vault.cachedRead() otherwise for better performance. | |
readBinary(file) | Read the content of a binary file stored inside the vault. | |
recurseChildren(root, cb) | static | |
rename(file, newPath) | Rename or move a file. To ensure links are automatically renamed, use FileManager.renameFile() instead. | |
trash(file, system) | Tries to move to system trash. If that isnโt successful/allowed, use local trash | |
trigger(name, data) | (Inherited from Events) | |
tryTrigger(evt, args) | (Inherited from Events) |