Templater - Renaming Files

What I’m trying to do

I’m trying to write some Templater code to automatically rename chapters to order them properly.

My current code is as follows:

<%
let chapter = 1;
while (true) {
if (tp.file.exists("Chapter " + chapter)) {
chapter++;
} else {
await tp.file.rename("Chapter " + chapter);
break;
}
}
%>

If anyone can help further

I’d also like to be able to add a title to the file name. Something like “Chapter 1 - Prologue” and any new files created from this template ignore anything after the number when trying to determine the chapter count.

This might be a decent starting place. The only piece you’d need to add it adding the custom name to the end, likely using tp.system.prompt.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.