Page 1 of 1
incrementing within a loop
Posted: 14 Nov 2006 07:12
by Matice
can something like to following be done?
set FILEID=0
for /f "tokens=*" %%f in (myhosts.txt) do (
%FILEID%=%FILEID% +1
echo do something to host >> %FILEID%.txt
)
Posted: 14 Nov 2006 09:38
by dizze
Yes,
but the command to execute would be:
set /a %FILEID%=%FILEID% + 1
Posted: 14 Nov 2006 10:11
by Matice
funny, i couldnt get it to work :/
dizze wrote:Yes,
but the command to execute would be:
set /a %FILEID%=%FILEID% + 1
Posted: 14 Nov 2006 10:16
by dizze
oops, obvious typo
set FILEID=0
set /a FILEID=%FILEID% + 1
DOH!
Posted: 14 Nov 2006 10:30
by Matice
yeah just noticed the same when i opened my eyes a bit!
anyhow thansk for the help!
Matice wrote:funny, i couldnt get it to work :/
dizze wrote:Yes,
but the command to execute would be:
set /a %FILEID%=%FILEID% + 1
Posted: 15 Nov 2006 05:34
by Matice
damn, i was wrong,
I couldnt get it to work in a for loop
any ideas?
any ideas whats wrong with the one below?
@echo off
cls
set FILEID=1
for /f "tokens=*" %%f in (myhosts.txt) do (
set /a FILEID=%FILEID% + 1
echo forking tasks for %%f with ID %FILEID%
)
Posted: 15 Nov 2006 19:12
by DosItHelp
Matice,
Try:
Code: Select all
@echo off
cls
set FILEID=1
for /f "tokens=*" %%f in (myhosts.txt) do (
set /a FILEID+=1
call echo forking tasks for %%f with ID %%FILEID%%
)
DOS IT HELP?
Good job helping out dizze!
Posted: 16 Nov 2006 04:22
by Matice
set /a FILEID+=1
never heard of such a syntax but that did the trick beautifully, now i can continue without probs! thanks a bunch!!
DosItHelp wrote:Matice,
Try:
Code: Select all
@echo off
cls
set FILEID=1
for /f "tokens=*" %%f in (myhosts.txt) do (
set /a FILEID+=1
call echo forking tasks for %%f with ID %%FILEID%%
)
DOS IT HELP?
Good job helping out dizze!