const path = require('path'); const fs = require('fs'); const dir = path.join(__dirname, 'docs'); fs.readdir(dir, (err, files) => { if (err) return console.log(`Unable to scan directory: ${dir}; ${err}`); //20190326-9120004734_20190314_2019326151232.xml1553612402 const re = /.*-(.*)\.(xml|txt)(\d+)/; files.forEach(file => { const m = re.exec(file); if (m) { const newName = `${m[1]}.${m[2]}`; console.log(`${file} => ${newName}`); fs.renameSync(path.join(dir, file), path.join(dir, newName)); } else { console.log('skipping:', file); } }); });
205300cookie-checkNodeJs rename files