Rename multiple filenames on the command line or batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
coraties
Posts: 1
Joined: 05 Jan 2012 16:41

Rename multiple filenames on the command line or batch file

#1 Post by coraties » 05 Jan 2012 16:49

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

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

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

#2 Post by !k » 08 Jan 2012 01:30

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
)

Post Reply