I am trying to develop a windows batch program where if error like The system cannot find the drive specified. or The system cannot find the path specified. comes, then “fld_chk.out” file can be checked and looping can happen.
But cd A:\rr\Br>fld_chk.out is not capturing these errors.
how to do capture there standard errors?
My code is like this:-
cd A:\rr\Br>fld_chk.out
cd B:\yy\dd>>fld_chk.out
find /c "The system cannot find" *.out>fld_count_check_1.out
find /c "0" fld_count_check_1.out>fld_count_check_2.out
FOR /F "TOKENS=1* DELIMS=:" %%B IN (fld_count_check_2.out) DO SET b=%%C
set _count=%b%
IF %_count% EQU 2 goto Success
IF not %_count% EQU 2 goto notSuccess
:Success
echo folder found
:notSuccess
echo folder not found
Thanks in advance
Sree
The way to do that is by checking %ERRORLEVEL% value after
cdcommand was executed:If the value is 0, CD was correctly executed and current directory be changed; otherwise (errorlevel==1) the drive or directory does not exist.
The
2> NULpart is to avoid that the error message appear in the screen.