I want to share a trick to bulk edit properties, as I haven’t seen it elsewhere.
The following code will add a created
property to every markdown file with their file creation time, except for notes under System/
folder.
- Open developer console with
Ctrl + Shift + i
- Paste this code into console
// Add "created" property to every note in the vault
app.vault.getMarkdownFiles() // Get all markdown files
.filter((tfile) => !tfile.path.startsWith("System/")) // Exclude notes
.forEach((tfile) => {
let ctime = moment(tfile.stat.ctime).format('YYYY-MM-DDTHH:mm:ss');
app.fileManager.processFrontMatter(tfile, (fm) => {fm['created'] = ctime});
});
- Hit
Enter
to execute the code
Executing code in console can have massive impact to your vault. Be sure to have version control or snapshot before executing any risky code.
This method can be applied to do any bulk edits, e.g., query files with Dataview, then do anything with resulting files. Though in many cases, mass edit with external editors might be easier.
I accidentally deleted my previous post, sorry for the repost.