1 | const fs = require("fs");
|
2 | const path = require("path");
|
3 | const cwd = process.cwd();
|
4 | const arg = process.argv;
|
5 |
|
6 | function main() {
|
7 | const prefix = arg[arg.length - 1];
|
8 | const files = fs.readdirSync(cwd).filter(it => /(jpe?g|png|gif)$/i.test(it));
|
9 | files.forEach((item, i) => {
|
10 | const oldName = path.join(cwd, item);
|
11 | const ext = path.extname(oldName);
|
12 | const index = `${i + 1}`.padStart(2, "0");
|
13 | const newName = path.join(cwd, `${prefix}_${index}${ext}`);
|
14 | fs.renameSync(oldName, newName);
|
15 | });
|
16 | }
|
17 |
|
18 | module.exports = ctx => {
|
19 | main(ctx);
|
20 | };
|