Get your own Node server
const fs = require('fs').promises;
const path = require('path');

async function batchRename() {
  const directory = 'images';
  const pattern = /^image(\d+)\.jpg$/;

  try {
    // Read directory contents
    const files = await fs.readdir(directory);

    // Process each file
    for (const file of files) {
      const match = file.match(pattern);
      if (match) {
        const [_, number] = match;
        const newName = `photo-${number.padStart(3, '0')}.jpg`;
        const oldPath = path.join(directory, file);
        const newPath = path.join(directory, newName);

        // Skip if the new name is the same as the old name
        if (oldPath !== newPath) {
          await fs.rename(oldPath, newPath);
          console.log(`Renamed: ${file} - ${newName}`);
        }
      }
    }

    console.log('Batch rename completed');
  } catch (err) {
    console.error('Error during batch rename:', err);
  }
}

batchRename();

              
Renamed: image3211.jpg - photo-3211.jpg
Renamed: image3212.jpg - photo-3212.jpg
Renamed: image3213.jpg - photo-3213.jpg
Renamed: image3214.jpg - photo-3214.jpg
Renamed: image3215.jpg - photo-3215.jpg
Renamed: image3216.jpg - photo-3216.jpg
Renamed: image3217.jpg - photo-3217.jpg
Renamed: image3218.jpg - photo-3218.jpg
Batch rename completed