Need help with Windows batch script
I have a hundred text files to which I would like to insert the numbers 1 to 100 at the end of each. the script below will add "some text here" to every file in a directory where the bat script is saved and executed.
FOR %%i IN (*.txt) DO echo some text here>&g开发者_高级运维t; %%i
Now, I want numbers 1-100 inserted into the said 100 text files instead of "some text here".
What is the correct script in order to achieve this?
if you look at for /?
FOR /L %variable IN (start,step,end) DO command [command-parameters]
The set is a sequence of numbers from start to end, by step amount. So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would generate the sequence (5 4 3 2 1)
@echo off
setlocal ENABLEDELAYEDEXPANSION
set count=0
FOR %%i IN (*.txt) DO (
set /A count = !count! + 1
echo !count! %%i
echo !count! >> %%i
)
The first echo prints the file names & the counter numbers that will be appended to each.
精彩评论