Counter in FOR LOOP

Eidos Hitman: blood money (ps2)
June 9, 2010 at 01:53:24
Specs: windows XP
Hi, I made a batch file that scans for a usb device. If it's not available it will prompt an error message(error.vbs script). There is a counter(get's it values from count.txt). If the usb is not available the counter will increase by 1. When the counter = 2, the error message will prompt(only when it's 2). The results are saved in a log file(log.txt). When the usb is available, the counter will be reset to 0. The problem is that in the ELSE statement the counter won't reset to 0... Can someone help me on this one please? thanks in advance


@ECHO off
setLocal EnableDelayedExpansion
cd\i386

for /f "tokens=* delims= " %%a in (count.txt) do (
set /a N+=1
set v!N!=%%a
)
set counter=!v1!
echo %counter%
@pause

For /f %%A in ('devcon find "USB\VID_0781*"') do (if %%A==No (
set /a counter+=1
echo !counter! > count.txt
@pause
) else (set /a counter = 0))

@pause
echo %date% %time% >> log.txt
devcon find hwids USB\VID_0781* >> log.txt

if !counter!==2 (start error.vbs)

@pause


See More: Counter in FOR LOOP

Report •


#1
June 9, 2010 at 06:56:36
might try it with these mod.s. I'm not sure exactly what your requirements / objectives are, so i might have misconstrued some interpretations, but this is my "take" on it thus far.
@ECHO off
setLocal EnableDelayedExpansion
cd\i386

:: this loads an array, but count never seems to have more than one line anyway?
:for /f "tokens=* delims= " %%a in (count.txt) do (
:set /a N+=1
:set v!N!=%%a)
:set counter=!v1!
:: you could substitute the foll. for above 3 lines, to de-complicate:
set /p counter=<count.txt
echo %counter%
@pause

For /f %%A in ('devcon find "USB\VID_0781*"') do (
if %%A==No (set /a counter+=1) else (set /a counter = 0)
)
:: echo out, regardless if its 0,1 or 2 ?
> count.txt echo %counter%
:: note that: echo %counter% > count.txt will include a trailing space!
@pause
echo %date% %time% >> log.txt
devcon find hwids USB\VID_0781* >> log.txt

if !counter! geq 2 (start error.vbs)

@pause


Report •

#2
June 9, 2010 at 07:05:32
thanx man for the solution, i have the program working now.

Report •

Related Solutions


Ask Question