Answers for "rename files in folder"

0

rename files in folder

const fs = require('fs');
var path = require("path");

let files = fs.readdirSync('./'); // get all files

files = files.filter(f => /^[1-9]{1}[.]/g.test(f)); // filter

const filesToRename = files.map(f => { // map
    return {
        name: path.resolve(f),
        new: path.resolve(0 + f)
    }
});

filesToRename.forEach(f => {
    fs.renameSync(f.name, f.new); // execute
})
Posted by: Guest on September-16-2021

Code answers related to "rename files in folder"

Code answers related to "Javascript"

Browse Popular Code Answers by Language