Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require("fs");
- const path = "./"; // current folder
- fs.readdir(path, function(err, items) {
- console.log('Old filenames:');
- console.log(items);
- for (var i = 0; i < items.length; i++) {
- const file = items[i];
- // only apply to jpg's in the folder
- if (file.substr(-3) === 'jpg'){
- // adjust this line to
- let newFilename = file.substring(file.indexOf('_', file.indexOf('_') + 1) + 1);
- console.log(`Renaming ${file} to ${newFilename}`);
- fs.rename(file,newFilename, (err) => {
- if (err) throw err;
- });
- console.log(newFilename);
- }
- }
- console.log('Finished');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement