I have a number of files to rename, I want to remove _thumb in existing name.

Eg: 00700008_thumb.jpg

I want to rename the above files as:

Eg: 00700008.jpg

Using below code how to separate the part.


SET SourceDir=F:\Square.....

FOR /F "TOKENS=1-3 DELIMS=. " %%F IN ('DIR /B /A-D "%SourceDir%\*.jpg"') DO (
  SET "part1=%%~F" 
  SET "part2=%%~G" 
  SET "part3=%%~H"
  REN "%SourceDir%\!part1! !part2!.!part3!" "00!part2!.!part3!"

How can I rename the files?

  • What's the result of the code you provided? Looks like you're already renaming the files? – Seth Sep 22 '16 at 9:29
  • 3
    This is the 6th time you have asked a very similar question. Please take some time to learn how the answers that you have been provided with solve the problems. You will then be able to make the required changes yourself in future. – DavidPostill Sep 22 '16 at 9:30
  • 2
    @Seth He's just pasting similar code from his other 5 questions and expecting us to tweak it every time. See my other comment. – DavidPostill Sep 22 '16 at 9:31

If your issue is to rename those files, according to your examples, you could just cd to the folder you want and issue the following command:

for /F "useback tokens=1 delims=_" %I IN (`dir /B /A-D *.jpg`) DO (ren %~I_thumb.jpg %~I.jpg)
  • This sounds good @m4573r – Ezhilarasan Sep 22 '16 at 10:12
  • @dbenham no it doesn't; see the delims=_? %I contains only 00700008. But I would consider making the dir *_thumb.jpg in case there are any other files around. – dave_thompson_085 Sep 22 '16 at 12:26
  • Oops, that was embarrassing. @dave_thompson_085 - Thanks for pointing out the DELIMS that I had missed. – dbenham Sep 22 '16 at 12:51

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.