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.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new FileManager(
app):FileManager
Defined in: file-manager.ts:49
Parameters
Section titled “Parameters”Returns
Section titled “Returns”FileManager
Properties
Section titled “Properties”
readonlyapp:App
Defined in: file-manager.ts:49
Methods
Section titled “Methods”createFile()
Section titled “createFile()”createFile(
path,data,options?):Promise<TFile>
Defined in: file-manager.ts:253
New-file intent; exclusive-capable hosts never fall back to overwrite.
Parameters
Section titled “Parameters”string
string | ArrayBuffer
options?
Section titled “options?”Partial<FileProperties>
Returns
Section titled “Returns”Promise<TFile>
generateMarkdownLink()
Section titled “generateMarkdownLink()”generateMarkdownLink(
file,sourcePath,subpath?,alias?):string
Defined in: file-manager.ts:369
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:271
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:248
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: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.
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?”FrontmatterMutationOptions
Write options.
Returns
Section titled “Returns”Promise<void>
Remarks
Section titled “Remarks”Example:
app.fileManager.processFrontMatter(file, (frontmatter) => { frontmatter["key1"] = value; delete frontmatter["key2"];});Throws
Section titled “Throws”YAMLParseError if the YAML parsing fails
Throws
Section titled “Throws”Any errors that your callback function throws
promptForDeletion()
Section titled “promptForDeletion()”promptForDeletion(
file):Promise<void>
Defined in: file-manager.ts:353
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<void>
renameFile()
Section titled “renameFile()”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.
Parameters
Section titled “Parameters”The file to rename
newPath
Section titled “newPath”string
The new path for the file
Returns
Section titled “Returns”Promise<void>
trashFile()
Section titled “trashFile()”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).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Promise<void>