Wednesday, July 5, 2017

windows - How to rename last part of file name



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



Eg: 00700008_thumb.jpg

00800104_thumb.jpg
01200004_thumb.jpg



I want to rename the above files as:



Eg: 00700008.jpg
00800104.jpg
01200004.jpg



Using below code how to separate the part.




@ECHO ON

SETLOCAL ENABLEDELAYEDEXPANSION
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!"
)
GOTO EOF


How can I rename the files?


Answer



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)


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...