Page 1 of 1

Rename multiple filenames on the command line or batch file

Posted: 05 Jan 2012 16:49
by coraties
Hi,

I'm trying to find a easy way to rename multiple filenames on the command line or using the batch file:

The original files like:

abc01.txt, abc02.txt ... abc15.txt

to

defgh01.txt, defgh02.txt ... defgh15.txt

or to

de01.txt de02.txt ... de15.txt

Thanks in advance,
- Coraties

Re: Rename multiple filenames on the command line or batch f

Posted: 08 Jan 2012 01:30
by !k

Code: Select all

@echo off &setlocal enableextensions

set "old=abc"
set "new=defgh"

for /f "delims=" %%f in ('dir /b/a-d "%old%??.*" ^|findstr /rc:[0-9][0-9]\.txt$') do (
   set "num=%%~nf"
   setlocal enabledelayedexpansion
   set "num=!num:~-2!"
   ren "%%f" "%new%!num!%%~xf"
   endlocal
)