FileManager
Defined in: obsidian.d.ts:1493
Manage the creation, deletion and renaming of files from the UI.
Constructors
new FileManager()
new FileManager():
FileManager
Returns
Properties
app
app:
App
Defined in: src/obsidian/augmentations/FileManager.d.ts:13
Reference to App
vault
vault:
Vault
Defined in: src/obsidian/augmentations/FileManager.d.ts:25
Reference to Vault
Methods
canCreateFileWithExt()
canCreateFileWithExt(
arg1
):unknown
Defined in: src/obsidian/augmentations/FileManager.d.ts:27
Parameters
arg1
unknown
Returns
unknown
createAndOpenMarkdownFile()
createAndOpenMarkdownFile(
path
,location
):Promise
<void
>
Defined in: src/obsidian/augmentations/FileManager.d.ts:34
Creates a new Markdown file in specified location and opens it in a new view
Parameters
path
string
Path to the file to create (missing folders will be created)
location
Where to open the view containing the new file
Returns
Promise
<void
>
createNewFile()
createNewFile(
location
?,filename
?,extension
?,contents
?):Promise
<TFile
>
Defined in: src/obsidian/augmentations/FileManager.d.ts:44
Create a new file in the vault at specified location
Parameters
location?
Location to create the file in, defaults to root
filename?
string
Name of the file to create, defaults to ‘Untitled’ (incremented if file already exists)
extension?
string
Extension of the file to create, defaults to ‘md’
contents?
string
Contents of the file to create, defaults to empty string
Returns
createNewFolder()
Defined in: src/obsidian/augmentations/FileManager.d.ts:50
Creates a new untitled folder in the vault at specified location
Parameters
location
Location to create the folder in, defaults to root
Returns
createNewMarkdownFile()
createNewMarkdownFile(
location
,filename
,contents
):Promise
<TFile
>
Defined in: src/obsidian/augmentations/FileManager.d.ts:54
Creates a new Markdown file in the vault at specified location
Parameters
location
filename
string
contents
string
Returns
createNewMarkdownFileFromLinktext()
createNewMarkdownFileFromLinktext(
filename
,path
):Promise
<TFile
>
Defined in: src/obsidian/augmentations/FileManager.d.ts:61
Creates a new Markdown file based on linktext and path
Parameters
filename
string
Name of the file to create
path
string
Path to where the file should be created
Returns
generateMarkdownLink()
generateMarkdownLink(
file
,sourcePath
,subpath
?,alias
?):string
Defined in: obsidian.d.ts:1529
Generate a Markdown link based on the user’s preferences.
Parameters
file
the file to link to.
sourcePath
string
where the link is stored in, used to compute relative links.
subpath?
string
A subpath, starting with #
, used for linking to headings or blocks.
alias?
string
The display text if it’s to be different than the file name. Pass empty string to use file name.
Returns
string
getAvailablePathForAttachment()
getAvailablePathForAttachment(
filename
,sourcePath
?):Promise
<string
>
Defined in: obsidian.d.ts:1563
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.
Parameters
filename
string
Name of the attachment being saved
sourcePath?
string
The path to the note associated with this attachment, defaults to the workspace’s active file.
Returns
Promise
<string
>
Full path for where the attachment should be saved, according to the user’s settings
getMarkdownNewFileParent()
getMarkdownNewFileParent(
path
):TFolder
Defined in: src/obsidian/augmentations/FileManager.d.ts:70
Gets the folder that new markdown files should be saved to, based on the current settings
Parameters
path
string
The path of the current opened/focused file, used when the user wants new files to be created in the same folder as the current file
Returns
getNewFileParent()
getNewFileParent(
sourcePath
,newFilePath
?):TFolder
Defined in: obsidian.d.ts:1504
Gets the folder that new files should be saved to, given the user’s preferences.
Parameters
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?
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
insertIntoFile()
insertIntoFile(
arg1
,arg2
,arg3
):unknown
Defined in: src/obsidian/augmentations/FileManager.d.ts:71
Parameters
arg1
unknown
arg2
unknown
arg3
unknown
Returns
unknown
iterateAllRefs()
iterateAllRefs(
callback
):void
Defined in: src/obsidian/augmentations/FileManager.d.ts:77
Iterate over all links in the vault with callback
Parameters
callback
(path
, link
) => void
Callback to execute for each link
Returns
void
mergeFile()
mergeFile(
file
,otherFile
,override
,atStart
):Promise
<void
>
Defined in: src/obsidian/augmentations/FileManager.d.ts:86
Merge two files
Parameters
file
File to merge to
otherFile
File to merge from
override
string
If not empty, will override the contents of the file with this string
atStart
boolean
Whether to insert text at the start or end of the file
Returns
Promise
<void
>
processFrontMatter()
processFrontMatter(
file
,fn
,options
?):Promise
<void
>
Defined in: obsidian.d.ts:1551
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
file
the file to be modified. Must be a Markdown file.
fn
(frontmatter
) => void
a callback function which mutates the frontmatter object synchronously.
options?
write options.
Returns
Promise
<void
>
Throws
YAMLParseError if the YAML parsing fails
Throws
any errors that your callback function throws
Example
promptForDeletion()
promptForDeletion(
file
):Promise
<void
>
Defined in: src/obsidian/augmentations/FileManager.d.ts:90
Prompt the user to delete a file
Parameters
file
Returns
Promise
<void
>
promptForFileDeletion()
promptForFileDeletion(
arg1
):Promise
<unknown
>
Defined in: src/obsidian/augmentations/FileManager.d.ts:91
Parameters
arg1
unknown
Returns
Promise
<unknown
>
promptForFileRename()
promptForFileRename(
file
):Promise
<void
>
Defined in: src/obsidian/augmentations/FileManager.d.ts:95
Prompt the user to rename a file
Parameters
file
Returns
Promise
<void
>
promptForFolderDeletion()
promptForFolderDeletion(
arg1
):Promise
<unknown
>
Defined in: src/obsidian/augmentations/FileManager.d.ts:96
Parameters
arg1
unknown
Returns
Promise
<unknown
>
renameFile()
renameFile(
file
,newPath
):Promise
<void
>
Defined in: obsidian.d.ts:1512
Rename or move a file safely, and update all links to it depending on the user’s preferences.
Parameters
file
the file to rename
newPath
string
the new path for the file
Returns
Promise
<void
>
renameProperty()
renameProperty(
oldKey
,newKey
):Promise
<void
>
Defined in: src/obsidian/augmentations/FileManager.d.ts:107
Rename’s a property for all notes currently that have the old key
Parameters
oldKey
string
newKey
string
Returns
Promise
<void
>
trashFile()
trashFile(
file
):Promise
<void
>
Defined in: obsidian.d.ts:1520
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
Returns
Promise
<void
>