Skip to content

Instantly share code, notes, and snippets.

@jdpilgrim
Last active November 30, 2022 10:34
Show Gist options
  • Save jdpilgrim/a62b4895a06a27415040ca523518f1c5 to your computer and use it in GitHub Desktop.
Save jdpilgrim/a62b4895a06a27415040ca523518f1c5 to your computer and use it in GitHub Desktop.
Obsidian QuickAdd script to copy a file into a sub folder with the same name. Handly to use with folder note plugin.
module.exports = async function moveFilesWithTag(params) {
const {
app,
quickAddApi: { suggester, yesNoPrompt },
} = params;
/* ... */
const { workspace, vault } = this.app;
const activeView = workspace.getActiveFile();
if (activeView) { // The active view might not be a markdown view
const folder = `${activeView.parent.path}/${activeView.basename}`
const folderAbstractFile = vault.getAbstractFileByPath(folder);
if(folderAbstractFile)
{}
else
{
await vault.createFolder(folder);
}
await app.fileManager.renameFile(
activeView,
`${folder}/${activeView.name}`
);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment