rename files in folder

Solutions on MaxInterview for rename files in folder by the best coders in the world

showing results for - "rename files in folder"
Adriana
22 Nov 2016
1const fs = require('fs');
2var path = require("path");
3
4let files = fs.readdirSync('./'); // get all files
5
6files = files.filter(f => /^[1-9]{1}[.]/g.test(f)); // filter
7
8const filesToRename = files.map(f => { // map
9    return {
10        name: path.resolve(f),
11        new: path.resolve(0 + f)
12    }
13});
14
15filesToRename.forEach(f => {
16    fs.renameSync(f.name, f.new); // execute
17})
similar questions
fs renaming files