Skip to content

FileManager

Defined in: file-manager.ts:22

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

new FileManager(app): FileManager

Defined in: file-manager.ts:23

App

FileManager

readonly app: App

Defined in: file-manager.ts:23

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

Defined in: file-manager.ts:305

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:224

string

string

string


getNewFileParent(sourcePath, newFilePath?): TFolder

Defined in: file-manager.ts:220

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:352

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.

Partial<FileProperties>

Write options.

Promise<void>

app.fileManager.processFrontMatter(file, (frontmatter) => {
frontmatter['key1'] = value;
delete frontmatter['key2'];
});
```;
#### Throws
YAMLParseError if the YAML parsing fails
#### Throws
Any errors that your callback function throws
***
### promptForDeletion()
> **promptForDeletion**(`file`): `Promise`\<`void`\>
Defined in: [file-manager.ts:289](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/file-manager.ts#L289)
#### Parameters
##### file
[`TAbstractFile`](TAbstractFile.md)
#### Returns
`Promise`\<`void`\>
***
### renameFile()
> **renameFile**(`file`, `newPath`): `Promise`\<`void`\>
Defined in: [file-manager.ts:246](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/file-manager.ts#L246)
Rename or move a file safely, and update all links to it depending on the
user's preferences.
#### Parameters
##### file
[`TAbstractFile`](TAbstractFile.md)
The file to rename
##### newPath
`string`
The new path for the file
#### Returns
`Promise`\<`void`\>
***
### trashFile()
> **trashFile**(`file`): `Promise`\<`void`\>
Defined in: [file-manager.ts:285](https://code.ju.ma/lapis-notes/lapis/src/branch/main/packages/api/src/lib/file-manager.ts#L285)
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).
#### Parameters
##### file
[`TAbstractFile`](TAbstractFile.md)
#### Returns
`Promise`\<`void`\>