Whenever Copilot writes a script that does exactly what I was hoping it to do, I will record them here.
import fs from "fs/promises";
async function renameMovies(dir) {
const files = await fs.readdir(dir);
for (const file of files) {
const match = /^(\d{4}) - (.*)\.\w+$/.exec(file);
if (match) {
const [, year, title] = match;
const newName = `${title} (${year}).${file.split(".").pop()}`;
await fs.rename(`${dir}/${file}`, `${dir}/${newName}`);
}
}
}