FileManager
Class: FileManager
Section titled “Class: FileManager”Defined in: file-manager.ts:22
High-level helpers for vault file operations that need metadata-aware follow-up work.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FileManager(
app):FileManager
Defined in: file-manager.ts:23
Parameters
Section titled “Parameters”Returns
Section titled “Returns”FileManager
Properties
Section titled “Properties”
readonlyapp:App
Defined in: file-manager.ts:23
Methods
Section titled “Methods”generateMarkdownLink()
Section titled “generateMarkdownLink()”generateMarkdownLink(
file,sourcePath,subpath?,alias?):string
Defined in: file-manager.ts:305
Generate a Markdown link based on the user’s preferences.
Parameters
Section titled “Parameters”The file to link to.
sourcePath
Section titled “sourcePath”string
Where the link is stored in, used to compute relative links.
subpath?
Section titled “subpath?”string
A subpath, starting with #, used for linking to headings
or blocks.
alias?
Section titled “alias?”string
The display text if it’s to be different than the file name. Pass empty string to use file name.
Returns
Section titled “Returns”string
getAvailablePathForAttachment()
Section titled “getAvailablePathForAttachment()”getAvailablePathForAttachment(
filename,sourcePath?):string
Defined in: file-manager.ts:224
Parameters
Section titled “Parameters”filename
Section titled “filename”string
sourcePath?
Section titled “sourcePath?”string
Returns
Section titled “Returns”string
getNewFileParent()
Section titled “getNewFileParent()”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.
Parameters
Section titled “Parameters”sourcePath
Section titled “sourcePath”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.
newFilePath?
Section titled “newFilePath?”string
The path to the file that will be newly created, used to infer what settings to use based on the path’s extension.
Returns
Section titled “Returns”processFrontMatter()
Section titled “processFrontMatter()”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.
Parameters
Section titled “Parameters”The file to be modified. Must be a Markdown file.
(frontmatter) => void
A callback function which mutates the frontmatter object synchronously.
options?
Section titled “options?”Partial<FileProperties>
Write options.
Returns
Section titled “Returns”Promise<void>
Example
Section titled “Example” 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 theuser'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`\>