例如, 将文件下的 0001.jpg, 0002.jpg?w=100&h=200 改为 *.jpg 格式 ;
###// nodejs 获得当前目录下文件名
const fs = require('fs')
const files = fs.readdirSync('./')
// 修改文件名称
function rename (oldPath, newPath) {
fs.rename(oldPath, newPath, function(err) {
if (err) {
throw err;
}
});
}
for (let index = 0; index < files.length; index++) {
const path = files[index];
rename(path, path.replace(/.png.*/, '.png'))
}
优雅的话,就得其他大佬来解答了。