Create link to last (previous) Daily in a new Daily


I have the Daily as well as the Templater plugin up and running.
When I open up a new Daily, it gets created from the template where I have Templater scripts in place.

What I want to achieve

I’d like to be able to create a link on top of the new Daily to the very last Daily entry (i.e. the previous Daily).

Things I have tried

I tried to get a list of the files in the current folder with this script:

let dailyFolder = tp.file.folder(true);
console.log('Current folder is: '+dailyFolder)
const fs = require('fs');

fs.readdir(dailyFolder, (err, files) => {
  files?.forEach(file => {

The current folder name is logged to console correctly, but for the forEach, I get the error message Uncaught TypeError: Cannot read properties of undefined (reading 'forEach'), so I guess files is null.

Unfortunately, my Google-foo failed on me, probably mainly because I don’t barely know JavaScript at all (as you probably can tell by now…)

So here’s the question:

How can I get a list of files in the given folder?

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