Move a linked file into the current folder
Published with Share Note 🔸 Part of Obsidian guides
- Add the below template and assign it to a hotkey.
- Put your cursor into a link as per the screenshot.
- Press the hotkey. It will move the linked file into the same folder as the currently open note.
(remove the space in < %*
at the start)
< %*
const editor = app.workspace.activeEditor
// Get the link at the current cursor position
const link = editor.editor.getClickableTokenAt(editor.editor.getCursor())
if (link?.type === 'internal-link') {
// Get the current folder
const currentFolder = editor.file.parent.path
// Get the linked TFile
const linkedFile = app.metadataCache.getFirstLinkpathDest(link.text, '')
// Move the linked file to the current folder
await app.fileManager.renameFile(linkedFile, currentFolder + '/' + linkedFile.name)
new Notice(linkedFile.basename + ' has been moved to ' + currentFolder)
}
-%>
Asked in this thread
- [Tiny Plugin Request] - Fast moving of Files (Oct 4, 2023)