Created
January 23, 2023 05:37
-
-
Save SpeedxPz/fe7d3072dfda1a4e0863d06492dbf3a2 to your computer and use it in GitHub Desktop.
Node.js script rename the anime filename order by original name to format 'SXXEXX.XXX'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
const SeasonNum = 1 // Change season Number | |
const baseDir = `./Season ${pad(SeasonNum, 2)}/`; | |
var files = fs.readdirSync(baseDir); | |
const prefix = `S${pad(SeasonNum, 2)}` | |
let counter = 1; | |
files.forEach(element => { | |
const destName = `${prefix}E${pad(counter, 2)}`; | |
const ext = element.split('.').pop(); | |
console.log(`Rename ${element} -> ${destName}.${ext}`); | |
counter++; | |
}); | |
const readline = require('readline').createInterface({ | |
input: process.stdin, | |
output: process.stdout | |
}); | |
readline.question('Are you sure? ', ans => { | |
if (ans == "y") { | |
let counter = 1; | |
files.forEach(element => { | |
const destName = `${prefix}E${pad(counter, 2)}`; | |
const ext = element.split('.').pop(); | |
console.log(`Rename ${baseDir}${element} -> ${baseDir}${destName}.${ext}`); | |
fs.renameSync(`${baseDir}${element}`, `${baseDir}${destName}.${ext}`); | |
counter++; | |
}); | |
} | |
readline.close(); | |
}); | |
function pad(num, size) { | |
var s = "000000000" + num; | |
return s.substr(s.length-size); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment