FileManager
Official
Manage the creation, deletion and renaming of files from the UI.
Import:
import { FileManager } from 'obsidian';Signature:
export class FileManagerConstructor
new FileManager(app: App)Constructor.
To get the constructor instance, use getFileManagerConstructor from obsidian-typings/implementations.
Properties
| Property | Type | Description | |
|---|---|---|---|
| app | App | Reference to the obsidian#App. | |
| fileParentCreatorByType | Record<string, (path: string) => TFolder> | Mapping of file extensions to functions that determine the parent folder for new files. | |
| inProgressUpdates | LinkUpdatesHandler[] | null | Currently in-progress link update operations, or null if none. | |
| updateQueue | PromisedQueue | Queue for processing link update operations sequentially. | |
| vault | Vault | Reference to the obsidian#Vault. |
Methods
| Method | Returns | Description | |
|---|---|---|---|
| canCreateFileWithExt(extension) | boolean | Check whether a file with the given extension can be created. | |
| createAndOpenMarkdownFile(path, location) | Promise<void> | Creates a new Markdown file in specified location and opens it in a new view. | |
| createNewFile(location?, filename?, extension?, contents?) | Promise<TFile> | Create a new file in the vault at specified location. | |
| createNewFolder(location) | Promise<TFolder> | Creates a new untitled folder in the vault at specified location. | |
| createNewMarkdownFile(location, filename, contents) | Promise<TFile> | Creates a new Markdown file in the vault at specified location. | |
| createNewMarkdownFileFromLinktext(filename, path) | Promise<TFile> | Creates a new Markdown file based on linktext and path. | |
| deleteProperty(property) | Promise<void> | Delete a frontmatter property from every note that uses it. | |
| downloadAttachmentsForNote(file) | Promise<void> | Download attachments for note. | |
| generateMarkdownLink(file, sourcePath, subpath?, alias?) | string | Generate a Markdown link based on the user's preferences. | |
| getAllLinkResolutions() | [] | Always returns an empty array. | |
| getAvailablePathForAttachment(filename, sourcePath?) | Promise<string> | Resolves a unique path for the attachment file being saved. Ensures that the parent directory exists and dedupes the filename if the destination filename already exists. | |
| getMarkdownNewFileParent(path) | TFolder | Gets the folder that new markdown files should be saved to, based on the current settings. | |
| getNewFileParent(sourcePath, newFilePath?) | TFolder | Gets the folder that new files should be saved to, given the user's preferences. | |
| getOrCreateFolder(path) | Promise<TFolder> | Gets an existing folder by case-insensitive path, creating it (and any missing parents) if absent. | |
| insertIntoFile(file, text, position?) | Promise<void> | Insert text into a file. | |
| iterateAllRefs(callback) | void | Iterate over all links in the vault with callback. | |
| mergeFile(file, otherFile, override, atStart) | Promise<void> | Merge two files. | |
| notifyForBulkUndo(records, duration?) | void | Shows a notice offering to undo a bulk file modification, reverting each file to its captured state. | |
| processFrontMatter(file, fn, options?) | Promise<void> | 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. | |
| promptForDeletion(file) | Promise<boolean> | Prompt the user to confirm they want to delete the specified file or folder. | |
| promptForFileDeletion(file) | Promise<void> | Prompt the user to delete a file. | |
| promptForFileRename(file) | Promise<void> | Prompt the user to rename a file. | |
| promptForFolderDeletion(folder) | Promise<void> | Prompt the user to delete a folder. | |
| promptForImageDownload(urls) | Promise<null | Record<string, TFile> | undefined> | Prompt the user to download an image. | |
| registerFileParentCreator(extension, location) | void | Register an extension to be the parent for a specific file type. | |
| renameFile(file, newPath) | Promise<void> | Rename or move a file or folder safely, and update all links to it depending on the user's preferences. | |
| renameProperty(oldKey, newKey) | Promise<void> | Rename's a property for all notes currently that have the old key. | |
| runAsyncLinkUpdate(linkUpdatesHandler) | Promise<void> | Run async link update. | |
| storeTextFileBackup(path, data) | void | Store text file backup. | |
| trashFile(file) | Promise<void> | 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). | |
| unregisterFileCreator(extension) | void | Unregister extension as root input directory for file type. | |
| updateAllLinks(links) | Promise<void> | Update all links. | |
| updateInternalLinks(data) | Promise<void> | Update internal links. |
Links to this page: