In article <wjamkca6nw8f.uq871imtep81$.
d...@40tude.net>,
JJ <
jj4p...@gmail.com> wrote:
>On Wed, 14 Jul 2021 07:19:03 -0700 (PDT), Peter wrote:
>> I was updating a batch file I wrote to backup one of my PCs. It kept
>> crashing at a certain point. For two days I tried various things to fix
>> it with no luck. I finally guessed at a fix which does work but I dont
>> understand what the problem was or why the fix works. Here are a few
>> lines from the batch file showing the original version.
>>
>> (Its basically a counter/timer loop. When the counter hits 5 seconds it
>> exits the loop and continues elsewhere in the batch file. Its the
>> bottom line that caused the crash.)
>>
>> =================================
>>:wait-Z
>> if %counter%==5 goto Start-N
>> timeout 1 > nul
>> set /A counter=%counter%+1
>> if not exist z:\transfer\batch goto wait-Z
>> =================================
>
>The `if` command would generate a syntax error if `%counter%` is
>empty/blank.
Yes, but that's not the line OP says is causing the problem.
OP says the "bottom" line caused the crash, and the bottom line is:
>> if not exist z:\transfer\batch goto wait-Z
Further commentary in the OP makes it clear that that line (the one that
ends with "wait-Z" is, indeed, the line that is causing the problem.
In any case, I think we should assume that OP knows what he is doing with
the "counter" variable, although it would, of course, be safer to test via:
if X%counter%==X5 goto Start-N
(Or any of the other standard batch file hacks that have arisen over the
years to deal with this issue...)
--
People sleep peaceably in their beds at night only because rough
men stand ready to do violence on their behalf.
George Orwell