Templater icon indicating copy to clipboard operation
Templater copied to clipboard

Create new folder

Open richukuttan opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. When I trigger a specific template, I'd like to automatically create a folder and move my new note into it. I know I can move using tp.file.move, but there's no way I know of (within Templater) to automate creation of folders. From the documentation, tp.file.create_new is specifically for creating a new file.

Describe the solution you'd like Add an api similar to tp.file.create_new,to create a new folder.

Describe alternatives you've considered I'm currently digging into the Obsidian App api or into javascript filehandling libraries, to see if a function there can be used. However, this leads to a mismatch where I use the tp.file.create_new function to create new files (because it's so simple), but need to use something much more complicated for a similar task (folder creation).

richukuttan avatar Nov 13 '21 22:11 richukuttan

Interesting and useful. Any news on that?

almogtzabari avatar Jan 19 '22 08:01 almogtzabari

I would like this as well, especially if move or create_new just created any missing folders for you.

For now I was able to get it working with app.vault.createFolder:

<%*
 let projectName = await tp.system.prompt("Project Name")
 let projectPath = `Projects/${projectName}`
 let tasksPath = `Projects/${projectName}/Tasks`
 await app.vault.createFolder(projectPath)
 await app.vault.createFolder(tasksPath)
 let tasksFolder = app.vault.getAbstractFileByPath(tasksPath)
 
 await tp.file.move(`${projectPath}/${projectName}`)
 let tasksTemplate = await tp.file.find_tfile("Project Tasks (Template)")
 let tasks = tp.file.create_new(tasksTemplate, "Tasks", false, tasksFolder)
-%>

samwarnick avatar Feb 24 '22 16:02 samwarnick