"Bond" <> wrote in message
news:ufgZ8$...
> Hi again!
>
> ...Continuing from my previous post. Since it spawned such a good
> conversation
I can't figure out how I can add a loop counter to my
> checking for an empty folder (which BTW I already had in my original code)
>
> In the example below you will see what I am trying to do unsuccessfully.
>
> For /l %%x in (1,1,10) do (
> For /d %%i in (\\%1\%3\%4) do (
> if exist %%i\*.xml goto :copy
> )
> choice /c YN /t 5 /d N /m "Do you want to stop processing of this
> batch?"
> set /a Count+=1
> echo %Count% times
> )
Try this:
@echo off
setlocal EnableDelayedExpansion
set count=0
For /l %%x in (1,1,10) do (
For /d %%i in (\\%1\%3\%4) do (
if exist %%i\*.xml goto :copy
)
choice /c YN /t 5 /d N /m "Do you want to stop processing of this
batch?"
set /a Count+=1
echo !Count! times
)
Your script has two problems:
- You never initialise the %count% variable. Sometimes you can get away with
this, sometimes you can't.
- All environmental variables inside the "For" loop are scanned and resolved
exactly once: When the whole "For" construct, up to the closing bracket, is
read by the command processor. If your code changes them on the fly then you
must force a rescan, which you do with the "EnableDelayedExpansion" and the
use of exclamation marks around your variables.
By the way - is it your intention to ask the same question ten times?