Templater
Templater copied to clipboard
Add "relative" to tp.file.exists
The basic enhancement I'd like is to add a "relative" parameter to tp.file.exists(file :String, relative: boolean = false). The effect of the parameter is to treat the file as a full path (relative to the vault folder, like what you get back from tp.file.folder(true)
I left some comments in https://github.com/SilentVoid13/Templater/discussions/333#discussioncomment-1302141.
The basic issue is that app.vault.createFolder(path) expects a path relative to the vault base folder. Similarly, tp.file.move expects a path relative to the vault base folder. However, tp.file.exists expects a path relative to the current folder.
This is problematic in the case when you are creating a file with the template and you want to move it in place. So, long as the file is created in the vault base folder ("/"), you're fine. But, for example, periodic notes often get created in a non-root directory.
Additionally, app.vault.createFolder(path) seems to create as many subfolders as it needs to fill out the path (a good thing IMO). However, if all of the subfolder exist, then it aborts the script with an error.
If I was writing a script that took a file in one location and wanted to move it to an entirely different location in another set of subfolders (which may not exist yet), checking for existence would be problematic. The above change to tp.file.exists would make things very easy.
+1, would really be a nice feature. As discussed here:
For now I'm using (await tp.file.exists(tp.file.folder(false) + "/" + tp.date.now("YYYY-MM", 0) + ".md")) and for me this doesn't look pretty