Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Math in a batch file (NT)
Name: Robin Siebler Date: June 26, 2003 at 13:41:00 Pacific OS: Win2k CPU/Ram: N/A
Comment:
I am trying to increment a counter as I loop through a section of a batch file. I tried using 'set /a' and incrementing a variable, but I could not figure out how to echo the value of the variable. Can someone tell me how to do this?
Name: Robin Siebler Date: June 26, 2003 at 13:48:51 Pacific
Reply:
After quite a bit of searching, I managed to find the answer to my question:
Environment variable that get evaluated within a FOR loop get expanded only at the beginning of the loop. So the following snippet does not produce the expected result:
set count=1 FOR /f "tokens=*" %%a in ('dir /b') do ( echo %count%: %%a set /a count+=1)
To force the variable to get evaluated at the proper iteration, use the new subroutine call mechanism to take the evaluation outside of the loop.
set count=1 FOR /f "tokens=*" %%a in ('dir /b') do ( call :exec echo %%count%%: %%a set /a count+=1) goto :EOF
Summary: Hi folks, Hoping someone out there can help me. Im trying to run a series of batch files, one after the other. At first I was hoping to be able to kick one off after the other by somehow when done...
Summary: I am trying to "kill" a process like in UNIX, but I don't know how it's done in NT outside of the GUI "Task Manager". My goal is to create a batch file that will do this. ...
Summary: ::------------------------------------------- ::Create a batch file called wait.bat ::add the following line below. ::For batch files that neeed to ::pause for a period of time. ::To use just at the...