-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpn
executable file
·34 lines (30 loc) · 907 Bytes
/
rpn
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
29
30
31
32
33
34
#!/usr/bin/env node
'use strict';
const fs = require('fs');
let basePath = process.cwd();
let [, , oldName, newName] = process.argv;
if(oldName && newName) {
if (oldName.indexOf('@') !== -1) {
oldName = oldName.split('@')[0];
}
if (oldName.indexOf('.') !== -1) {
oldName = oldName.split('.')[0];
}
for (let i = 1; i < 4; i++) {
let oldFileName = i>1? `${oldName}@${i}x.png` : `${oldName}.png`;
let newFileName = i>1? `${newName}@${i}x.png` : `${newName}.png`;
let oldPath = `${basePath}/${oldFileName}`;
let newPath = `${basePath}/${newFileName}`;
fs.rename(oldPath,newPath,(err)=> {
if(err) {
console.error(err);
}
else {
console.log(`${oldFileName}重命名为${newFileName}`)
}
})
}
}
else{
console.log('请输入文件名');
}