Replacing text in file names

July 15, 2011 at 07:22:08
Specs: Windows XP
I want to rename all my files in the current directory of the BAT file, replacing 11 to 12, if there's more then one occurrence of it, it will replace only the first occurrence.

For example the following three files >
11-2011.txt
11-2012.txt
11-2013.txt

will become
12-2011.txt
12-2012.txt
12-2013.txt

notice that the file 11-2011.txt has twice "11".

Thanks!


See More: Replacing text in file names

Report •


#1
July 16, 2011 at 09:26:56
@echo off
for /f "tokens=1,* delims=-" %%a in ('dir *.txt /b ^| find "11"') do (
set /a Num=%%a+1
ren %%a-%%b !Num!-%%b
)

Report •
Related Solutions


Ask Question