incrementing within a loop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Matice
Posts: 14
Joined: 14 Nov 2006 02:48

incrementing within a loop

#1 Post by Matice » 14 Nov 2006 07:12

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
)

dizze
Posts: 10
Joined: 12 Jul 2006 07:53
Contact:

#2 Post by dizze » 14 Nov 2006 09:38

Yes,

but the command to execute would be:

set /a %FILEID%=%FILEID% + 1

Matice
Posts: 14
Joined: 14 Nov 2006 02:48

#3 Post by Matice » 14 Nov 2006 10:11

funny, i couldnt get it to work :/

dizze wrote:Yes,

but the command to execute would be:

set /a %FILEID%=%FILEID% + 1

dizze
Posts: 10
Joined: 12 Jul 2006 07:53
Contact:

#4 Post by dizze » 14 Nov 2006 10:16

oops, obvious typo

set FILEID=0
set /a FILEID=%FILEID% + 1

DOH!

Matice
Posts: 14
Joined: 14 Nov 2006 02:48

#5 Post by Matice » 14 Nov 2006 10:30

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

Matice
Posts: 14
Joined: 14 Nov 2006 02:48

#6 Post by Matice » 15 Nov 2006 05:34

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%
)

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#7 Post by DosItHelp » 15 Nov 2006 19:12

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? :wink:

Good job helping out dizze!

Matice
Posts: 14
Joined: 14 Nov 2006 02:48

#8 Post by Matice » 16 Nov 2006 04:22

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? :wink:

Good job helping out dizze!

Post Reply