Templater to create a file and move the file under the same name folder?

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

  1. prompt to input a name of the note
  2. create a folder using the input text
  3. prompts to choose from lists and use them as meta
  4. combine a name for another file under the created folder
  5. create another file using the combined name under the created folder
  6. move this note to the created folder (with MAKE.md this note under the same name folder will be rendered as the folder note instead of a plain note)

Things I have tried

let PJname = tp.file.title;
if (PJname.startsWith(“Untitled”)) {
PJname = await tp.system.prompt(“Title of the Note:”, throw_on_cancel = true);
await tp.file.rename(PJname);
let PJFolderName = “01 Projects/” + PJname;
await this.app.vault.createFolder(PJFolderName);
let PJFolder = app.vault.getAbstractFileByPath(PJFolderName);

let PJstatus = await tp.system.suggester(item => item,[“:red_circle: not started”, “:yellow_circle: in progress”, “:green_circle: done”], [“:red_circle: not started”, “:yellow_circle: in progress”, “:green_circle: done”], "Status: ");
let PJtype = await tp.system.suggester(item => item,[“personal”, “work”], [“personal”, “work”], "Type: ");
let PJpriority = await tp.system.suggester(item => item,[“:arrow_up_small: high”, “:record_button: mid”, “:arrow_down_small: low”, “:triangular_flag_on_post: Urgent”], [“:arrow_up_small: high”, “:record_button: mid”, “:arrow_down_small: low”, “:triangular_flag_on_post: urgent”], "Priority: ");

let kanbanFileName = PJname + “_Kanban”;
await tp.file.create_new(tp.file.find_tfile(“03 Resources/Project Kanban”), kanbanFileName, false, PJFolder);

await tp.file.move(PJFolder, tp.file.title);

Result: The “path” argument must be of type string. Received undefined

Why the PJFolder can be used to create another file but can not be used as the path to move the file to?

1 Like

Welcome! Not sure if this is the issue or whether there may be another problem, but I wonder whether the error results from not providing the file name in the path. Also, you can fence the code with three backticks on the line before and three backticks on the line after in order to format it on the forum.

The following is pasted from the Templater documentation:

tp.file.move(new_path: string, file_to_move?: TFile)

Moves the file to the desired vault location.

  • new_path: The new vault relative path of the file, without the file extension. Note: the new path needs to include the folder and the filename, e.g. /Notes/MyNote

I hope this helps!

I tried to put the filename which should be PJname to the path.

await tp.file.move(“PJFolder/PJname”, tp.file.title);

But still got the same error: The “path” argument must be of type string. Received undefined
and even it created a “PJname” folder under the root of my vault…

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