Last active
February 6, 2016 15:09
-
-
Save 2Pacalypse-/4afad5d0b231d3cc0999 to your computer and use it in GitHub Desktop.
Renames replays from TL tournament system to be under 32 characters in length.
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
import fs from 'fs' | |
fs.readdir('.', (err, files) => { | |
if (err) { | |
console.log('err: ' + err) | |
return | |
} | |
files.forEach((file) => { | |
if (!file.endsWith('.rep')) { | |
console.log(file + ' is not a replay.') | |
return | |
} | |
const roundNumber = file.slice(1, 2) | |
const gameNumber = file.slice(-5, -4) | |
const index = file.indexOf('_vs_') | |
if (index === -1) { | |
console.log(file + ' is in wrong filename format') | |
return | |
} | |
let player1 = file.slice(3, index) | |
let player2 = file.slice(index + 4, -11) | |
if (player1.length > 9) { | |
player1 = player1.slice(0, 9) | |
} | |
if (player2.length > 9) { | |
player2 = player2.slice(0, 9) | |
} | |
const newFile = 'R' + roundNumber + '_' + player1 + '_v_' + player2 + '_G' + gameNumber + '.rep' | |
if (newFile.length > 31) { | |
console.log(newFile + ' is still too long. Rename it manually please.') | |
return | |
} | |
fs.rename(file, newFile, () => console.log('Renamed ' + file + ' -> ' + newFile)) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment