Skip to content

Instantly share code, notes, and snippets.

@masumskaib396
Created April 25, 2020 09:47
Show Gist options
  • Save masumskaib396/37876748b875d78f7432e4c0e981d225 to your computer and use it in GitHub Desktop.
Save masumskaib396/37876748b875d78f7432e4c0e981d225 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const path = require('path');
const filePath = 'file path name';
const files = fs.readdirSync(filePath).filter((file) => file.endsWith('.png'));
let count = 1;
const extName = '.png';
files.forEach((file) => {
const oldPath = path.join(filePath, file);
const newPath = path.join(filePath, count + extName);
fs.renameSync(oldPath, newPath);
console.log('Done', count, '...');
count++;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment