-
Notifications
You must be signed in to change notification settings - Fork 2
/
rename-icons.js
28 lines (25 loc) · 868 Bytes
/
rename-icons.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const fs = require('fs');
const args = process.argv.slice(2);
if (args[0]) {
const iconDirectory = args[0].slice(-1) == '/' ? args[0].slice(0, args[0].length - 1) : args[0];
let iconCounter = 0,
iconSetName = iconDirectory.split('/').pop();
fs.readdirSync(iconDirectory).forEach(file => {
const fileExtension = file.split('.').pop();
if (
fileExtension == 'png' ||
fileExtension == 'jpeg' ||
fileExtension == 'jpg' ||
fileExtension == 'gif' ||
fileExtension == 'svg'
) {
const sourceFile = `${iconDirectory}/${file}`,
newFile = `${iconDirectory}/${iconSetName}_${iconCounter}.${fileExtension}`;
console.log('Renaming ', sourceFile, ' -> ', newFile);
fs.renameSync(sourceFile, newFile);
iconCounter++;
}
});
} else {
console.log('Please include the icon folder path (e.g. Icons/FC) as first argument after filename');
}