使用Node批量重命名文件
'use strict'
let fs = require('fs')
let path = require('path')
let pathname = path.resolve('./') + '/test'
fs.readdir(pathname, (err, files) => {
files.forEach((filename, index) => {
let oldpath = pathname + '/' + filename
let newpath = pathname + '/' + index + '.txt'
fs.rename(oldpath, newpath, (err) => {
if (!err) {
console.log('success')
}
})
})
})