File Module

This module contains every internal function related to files.


Function documentation is using a specific syntax. More information here


Retrieves the file's content

tp.file.create_new(template: TFile ⎮ string, filename?: string, open_new: boolean = false, folder?: TFolder)

Creates a new file using a specified template or with a specified content.

  • filename: The filename of the new file, defaults to "Untitled".

  • folder: The folder to put the new file in, defaults to obsidian's default location. If you want the file to appear in a different folder, specify it with app.vault.getAbstractFileByPath("FOLDERNAME")

  • open_new: Whether to open or not the newly created file. Warning: if you use this option, since commands are executed asynchronously, the file can be opened first and then other commands are appended to that new file and not the previous file.

  • template: Either the template used for the new file content, or the file content as a string. If it is the template to use, you retrieve it with tp.file.find_tfile(TEMPLATENAME)

tp.file.creation_date(format: string = "YYYY-MM-DD HH:mm")

Retrieves the file's creation date.

  • format: Format for the date, refer to format reference

tp.file.cursor(order?: number)

Sets the cursor to this location after the template has been inserted.

You can navigate between the different tp.file.cursor using the configured hotkey in obsidian settings.

  • order: The order of the different cursors jump, e.g. it will jump from 1 to 2 to 3, and so on. If you specify multiple tp.file.cursor with the same order, the editor will switch to multi-cursor.

tp.file.cursor_append(content: string)

Appends some content after the active cursor in the file.

  • content: The content to append after the active cursor

tp.file.exists(filename: string)

The filename of the file we want to check existence. The fullpath to the file, relative to the Vault and containing the extension, must be provided. e.g. MyFolder/SubFolder/MyFile.

  • filename: The filename of the file we want to check existence, e.g. MyFile.

tp.file.find_tfile(filename: string)

Search for a file and returns its TFile instance

  • filename: The filename we want to search and resolve as a TFile

tp.file.folder(relative: boolean = false)

Retrieves the file's folder name.

  • relative: If set to true, appends the vault relative path to the folder name.

Includes the file's link content. Templates in the included content will be resolved.

  • include_link: The link to the file to include, e.g. [[MyFile]], or a TFile object. Also supports sections or blocks inclusions, e.g. [[MyFile#Section1]]

tp.file.last_modified_date(format: string = "YYYY-MM-DD HH:mm")

Retrieves the file's last modification date.

  • format: Format for the date, refer to format reference.

tp.file.move(new_path: string, file_to_move?: TFile)

Moves the file to the desired vault location.

  • new_path: The new vault relative path of the file, without the file extension. Note: the new path needs to include the folder and the filename, e.g. /Notes/MyNote

tp.file.path(relative: boolean = false)

Retrieves the file's absolute path on the system.

  • relative: If set to true, only retrieves the vault's relative path.

tp.file.rename(new_title: string)

Renames the file (keeps the same file extension).

  • new_title: The new file title.


Retrieves the active file's text selection.


Retrieves the file's tags (array of string)


Retrieves the file's title.


File content: <% tp.file.content %>

File creation date: <% tp.file.creation_date() %>
File creation date with format: <% tp.file.creation_date("dddd Do MMMM YYYY HH:mm") %>

File creation: [[<% (await tp.file.create_new("MyFileContent", "MyFilename")).basename %>]]

File cursor: <% tp.file.cursor(1) %>

File cursor append: <% tp.file.cursor_append("Some text") %>
File existence: <% await tp.file.exists("MyFolder/") %>
File existence of current file: <% await tp.file.exists(tp.file.folder(true)+"/"+tp.file.title+".md") %>

File find TFile: <% tp.file.find_tfile("MyFile").basename %>
File Folder: <% tp.file.folder() %>
File Folder with relative path: <% tp.file.folder(true) %>

File Include: <% tp.file.include("[[Template1]]") %>

File Last Modif Date: <% tp.file.last_modified_date() %>
File Last Modif Date with format: <% tp.file.last_modified_date("dddd Do MMMM YYYY HH:mm") %>

File Move: <% await tp.file.move("/A/B/" + tp.file.title) %>
File Move + Rename: <% await tp.file.move("/A/B/NewTitle") %>

File Path: <% tp.file.path() %>
File Path with relative path: <% tp.file.path(true) %>

File Rename: <% await tp.file.rename("MyNewName") %>
Append a "2": <% await tp.file.rename(tp.file.title + "2") %>

File Selection: <% tp.file.selection() %>

File tags: <% tp.file.tags %>

File title: <% tp.file.title %>
Strip the Zettelkasten ID of title (if space separated): <% tp.file.title.split(" ")[1] %>