Skip to content

FileManager

API reference uses a reviewed source snapshot. Source links open the published source; unverified line locations are omitted.

Defined in: file-manager.ts:48

High-level helpers for vault file operations that need metadata-aware follow-up work.

new FileManager(app): FileManager

Defined in: file-manager.ts:49

App

FileManager

readonly app: App

Defined in: file-manager.ts:49

createFile(path, data, options?): Promise<TFile>

Defined in: file-manager.ts:253

New-file intent; exclusive-capable hosts never fall back to overwrite.

string

string | ArrayBuffer

Partial<FileProperties>

Promise<TFile>


generateMarkdownLink(file, sourcePath, subpath?, alias?): string

Defined in: file-manager.ts:369

Generate a Markdown link based on the user’s preferences.

TFile

The file to link to.

string

Where the link is stored in, used to compute relative links.

string

A subpath, starting with #, used for linking to headings or blocks.

string

The display text if it’s to be different than the file name. Pass empty string to use file name.

string


getAvailablePathForAttachment(filename, sourcePath?): string

Defined in: file-manager.ts:271

string

string

string


getNewFileParent(sourcePath, newFilePath?): TFolder

Defined in: file-manager.ts:248

Gets the folder that new files should be saved to, given the user’s preferences.

string

The path to the current open/focused file, used when the user wants new files to be created ‘in the same folder’. Use an empty string if there is no active file.

string

The path to the file that will be newly created, used to infer what settings to use based on the path’s extension.

TFolder


processFrontMatter(file, fn, options?): Promise<void>

Defined in: file-manager.ts:416

Atomically read, modify, and save the frontmatter of a note. The frontmatter is passed in as a JS object, and should be mutated directly to achieve the desired result.

Remember to handle errors thrown by this method.

TFile

The file to be modified. Must be a Markdown file.

(frontmatter) => void

A callback function which mutates the frontmatter object synchronously.

FrontmatterMutationOptions

Write options.

Promise<void>

Example:

app.fileManager.processFrontMatter(file, (frontmatter) => {
frontmatter["key1"] = value;
delete frontmatter["key2"];
});

YAMLParseError if the YAML parsing fails

Any errors that your callback function throws


promptForDeletion(file): Promise<void>

Defined in: file-manager.ts:353

TAbstractFile

Promise<void>


renameFile(file, newPath): Promise<void>

Defined in: file-manager.ts:293

Rename or move a file safely, and update all links to it depending on the user’s preferences.

TAbstractFile

The file to rename

string

The new path for the file

Promise<void>


trashFile(file): Promise<void>

Defined in: file-manager.ts:344

Remove a file or a folder from the vault according the user’s preferred ‘trash’ options (either moving the file to .trash/ or the OS trash bin).

TAbstractFile

Promise<void>