nodejs批量修改文件名
下了一部甄嬛传的资源,但是因为文件名太长,在电视上看不到是第几集,所以批量修改一下
下载后的文件格式:
下载的文件路径:
批量修改文件名的代码
const fs = require("fs")
const path = require("path")
const dirPath = "E:/share/甄嬛传/"
const fileNameList = fs.readdirSync(dirPath)
fileNameList.forEach((fileName) => {
const newFileName = '甄嬛传' + fileName.split('2011.E')[1].substring(0, 2) + '.mp4'
// console.log(newFileName)
fs.rename(path.join(dirPath, fileName), path.join(dirPath, newFileName), function (err) {
if (err) {
throw err
} else {
console.log("Successfully renamed the file!", newFileName)
}
})
})
nodejs批量修改文件名
http://xuyuanhang.com//archives/1703996520505