I have two folders with the following images

  1. Original images
    • Customer-Engagement-Small
    • engineer
    • first-aid-kit
  2. Optimized images
    • Customer-Engagement-Small_70e76dfedeadb41a97636ca7006a5953
    • engineer_6bab3639c8cde4ef2c7ab4b8eafb888b
    • first-aid-kit_bd2d3ee1bb7a5632c66c4f269409e9ab

This is a sample. But I have thousands of files in these folder

My current workflow is:

  1. Click on an image
  2. Press F2
  3. Copy file name and paste to other files

It takes so much time. Is there a shorter way?
How do I rename these folder images to first ones.

Note: All the files in same order

  • Welcome to Superuser, from what it looks like all your files have a 32 characters long suffix. Together with the underline it is 33. Wouldn't a program or script which just removes the last 33 characters fulfill your needs? Or are there other name changes which do not fit into this pattern? – nixda May 11 '18 at 8:51

You can use this code to rename your optimized images by deleting everything that's after the underline "_" (if your files don't have two underlines).

@echo off
for /F "delims=" %%I in ('dir /A-D /B *_* 2^>nul') do (
    for /F "tokens=1 delims=_ " %%J in ("%%~nI") do ren "%%I" "%%J%%~xI"

Put this code in a text editor and save it as anyname.bat in the Optimized images folder and run it. Make a copy of your folder first.

  • Thanks For Your Solution I think this one is correct. but i need little bit change in this code... Check the name from behind and remove texts after ("_").. Bcoz some file name contain two underlines so i need to remove from backward any suggests please.. – Shriram Jun 19 '18 at 12:06

I do it using these steps:

  1. Create list of source files using command Dir /on /b > source.txt
  2. Create list of target file names using command Dir /on /b > Target.txt
  3. Open MS excel
  4. Open Source.txt and copy all names in column B of MS Excel sheet.
  5. Open Target.txt and copy all names in column C of MS Excel sheet.
  6. Fill column A with DOS command REN.
  7. Copy values of all three columns and paste in Notepad and save the file with extension .bat.
  8. Execute this batch file in source folder.

enter image description here

In order to get it done successfully, number of file and file order must match.

  • Using Excel to simulate "Rectangle Editing"... interesting solution! Only problem is that it isn't recursive. – T Nierath May 11 '18 at 8:56
  • @TNierath Thanks for pointing that out. However, we can make it work for sub-folders as well. That would need additional steps of find and replace and possibly macro in Notepad++. To get path of all sub-folders Dir /s /on /b command can be used. – Sandeep May 11 '18 at 9:28

Check out https://www.howtogeek.com/111859/how-to-batch-rename-files-in-windows-4-ways-to-rename-multiple-files/

"Bulk Rename Utility" or "Advanced Renamer" should satisfy your needs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.