How do I rename multiple files by removing a particular name, whitespace and add a unique string?
In the below example I used a FOR /F loop to set delimiters and tokens parsing file name parts and use those to set variables for later use with the REN command. I've also utilized the Setlocal EnableDelayedExpansion to handle the expanding of the variables set in the loop accordingly to be properly used (not parsed at runtime) with the rename command per iteration within the loop.
@ECHO ON
SETLOCAL ENABLEDELAYEDEXPANSION
SET SourceDir=C:\Users\User\Desktop\Tester
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
Further Resources
- FOR /F
- Setlocal EnableDelayedExpansion
- REN
I rename files a lot, and I find it very convenient to use Bulk Rename Utility. It is free. You can rename files and folders in folders and/or subfolders in many ways, including changing the extensions.