Batch script to remove parts of a filename

user2840728 picture user2840728 · Oct 3, 2013 · Viewed 14.5k times · Source

Help please!

I need to remove time stamp and file number off of the filename using a windows batch script. Thank you! Thank you in advance!

OLD Filename= CAM168-NOTSET.2013.10.01.18.45.45.882.jpg

NEW Filename= CAM168-NOTSET.jpg

Answer

Magoo picture Magoo · Oct 3, 2013
@ECHO OFF
SETLOCAL
SET "fname=CAM168-NOTSET.2013.10.01.18.45.45.882.jpg"
FOR %%i IN ("%fname%") DO FOR /f "delims=." %%j IN ("%%i") DO ECHO REN "%%~i" "%%~j%%~xi"
GOTO :EOF

New name merely ECHOed.