修改文件名
// 引入fs文件处理模块
var fs = require("fs");
var paths = ['chart-orange', 'chart-purple', 'chart-red', 'chart-yellow', 'number-blue', 'number-red', 'title-blue', 'title-red']
paths.forEach((path) => {
fs.readdir(path, function (err, files) {
// files是名称数组
files.forEach(function (filename, index) {
//运用正则表达式替换oldPath中不想要的部分
var oldPath = path + '/' + filename,
newPath = path + '/' + `${path}-${filename}`;
console.log(newPath);
fs.rename(oldPath, newPath, function (err) {
if (!err) {
console.log(filename + '副本替换成功!')
}
})
})
})
})