Skip to content

Instantly share code, notes, and snippets.

@Friss
Last active March 17, 2023 03:08
Show Gist options
  • Save Friss/39f6cec100cab98469649c0d1823bdd6 to your computer and use it in GitHub Desktop.
Save Friss/39f6cec100cab98469649c0d1823bdd6 to your computer and use it in GitHub Desktop.
const fs = require('fs').promises;
const convertToGropro = (index, id) => {
return `GH${index.padStart(2,'0')}000${id}`
}
const renameFiles = async (files, filePath, id) => {
files.sort();
for (let index = 0; index < files.length; index++) {
const file = files[index];
const newName = `${convertToGropro(`${index+1}`, id)}.MP4`;
console.log(`Renaming ${file} to ${newName}`)
await fs.rename(`${filePath}/${file}`, `${filePath}/${newName}`)
}
}
const main = async () => {
const frontSessions= [...await fs.readdir('./Front')].filter(file => !file.startsWith('.'));
const backSessions = [...await fs.readdir('./Back')].filter(file => !file.startsWith('.'));
for (let index = 0; index < frontSessions.length; index++) {
const sessionFolder = frontSessions[index];
const folderPath = `./Front/${sessionFolder}`;
console.log(folderPath)
const filesInSession = (await fs.readdir(folderPath)).filter(file => !file.startsWith('.'));
await renameFiles(filesInSession, folderPath, Math.max(index, 1));
}
for (let index = 0; index < backSessions.length; index++) {
const sessionFolder = backSessions[index];
const folderPath = `./Back/${sessionFolder}`;
console.log(folderPath)
const filesInSession = (await fs.readdir(folderPath)).filter(file => !file.startsWith('.'));
await renameFiles(filesInSession, folderPath, Math.max(index, 1));
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment