Skip to content

[!abstract] Purpose




LIST
WHERE file.folder = this.file.folder AND file.name != this.file.name
SORT file.name ASC

<%*
// --- AUTO-RENAME SCRIPT v2 ---
// This version is more robust and will not fail on folders without underscores.

const folderName = tp.file.folder();
let baseName = folderName; // Default to the full folder name.

// Only try to split the name if an underscore exists.
if (folderName.includes(’_’)) {
// This part is the same as before, but now it’s safely inside an ‘if’ block.
const parts = folderName.split(”);
if (parts.length > 1) {
baseName = parts[1].trim().split(’ ’)[0];
}
}

// Construct the new filename using simple, safe string addition.
const newFileName = ‘_index-’ + baseName;

// Rename the current file.
await tp.file.rename(newFileName); %>