I am trying to write a batch file for Windows 7 that will create 100 text files with names – ex1 to ex100. In each file i need to replace a given text (eg. ex3) with the same text as the name of the file.
So far I have managed to get the batch file to create the 100 files however the text (ex3) is replaced by ex1 in each file.
Here is the code that I have used. I am a complete novice to this and have cobbled it together from bits that I have found.
@echo off
setlocal enabledelayedexpansion
FOR /F "usebackq delims=" %%G IN ("c:\batch\batch.txt") DO (
Set Line=%%G
Set Line=!Line:"='!
Call:replace "!Line!"
)
pause
goto:eof ------------
:replace subroutine
(Set Line=%*&Set Line=!Line:~1,-1!)
Set Line=!Line:'="!
For /l %%A in (7,1,100) do Set "Line=!Line:ex3=ex%%A!"
For /l %%n in (1,1,100) do echo.!Line! >>"c:\batch\ex%%n.txt"
goto:eof ------------
Any suggestions?
Wow – that code is way more convoluted than is needed (and also slow because of CALL).