Is it possible to copy files (not move) files from one folder to another with a template? I work with word doc templates which are in a folder. I frequently end up copy and pasting them into a working folder, and it would be nice if i could automate this process.
+1 I would really like to know if this is possible too!
Maybe using templater’s obsidian commands: tp.obsidian
might be a way to do this?
I found something for move, but not copy
here is the solution
<%*
const folderPath = "path/to/your/folder"; // Replace with your target folder path
const currentFilePath = tp.file.path(true); // Get the full path of the current file
const currentFileName = tp.file.title; // Get the current file title
let currentContent = await app.vault.adapter.read(currentFilePath); // Read the content directly
// Find the position where the script starts
const scriptStart = currentContent.indexOf('<%*');
if (scriptStart !== -1) {
currentContent = currentContent.substring(0, scriptStart); // Exclude the script portion
}
const newFileName = `${currentFileName}`;
const newFilePath = `${folderPath}/${newFileName}.md`;
await app.vault.create(newFilePath, currentContent);
%>
1 Like