conditional proccessing symbols question

  • Thread starter Thread starter djc
  • Start date Start date
D

djc

this is a copy/paste from the windows help file:

when it says 'only if the command preceding the symbol is successfull' or
'only if the command preceding the symbol fails' what exactly constitutes
'successfull'? Is it the same thing as errorlevel? any error level other
that 0 is failed? or would for example a copy command completing with an
error level still be considered successfull completion of the command?

could I use something like this:

xcopy c:\file1 d:\file2 && SET MyVar=Success
IF %MyVar%==Success (
ECHO success >> c:\log.txt
) ELSE (
ECHO failed >> c:\og.txt
)

any info is greatly appreciated. Thanks.
 
djc said:
xcopy c:\file1 d:\file2 && SET MyVar=Success
IF %MyVar%==Success (

If the xcopy command failed then %MyVar% would not be defined and you'd get
a syntax error. So, this would work:
setlocal
xcopy c:\file1 d:\file2 && SET MyVar=Success
IF "%MyVar%"=="Success" (
ECHO success>> c:\log.txt
) ELSE (
ECHO failed>> c:\log.txt
)

Alternately:
setlocal
set MyVar=nothing
xcopy c:\file1 d:\file2 && SET MyVar=Success
IF %MyVar%==Success (
ECHO success
) ELSE (
ECHO failed
)

But more easily:
xcopy c:\file1 d:\file2
if ERRORLEVEL 1 (
echo failed>> c:\log.txt
) else (
echo success>> c:\log.txt
)
No need to set any variables.
 
Thanks.

Paul R. Sadowski said:
If the xcopy command failed then %MyVar% would not be defined and you'd get
a syntax error. So, this would work:
setlocal
xcopy c:\file1 d:\file2 && SET MyVar=Success
IF "%MyVar%"=="Success" (
ECHO success>> c:\log.txt
) ELSE (
ECHO failed>> c:\log.txt
)

Alternately:
setlocal
set MyVar=nothing
xcopy c:\file1 d:\file2 && SET MyVar=Success
IF %MyVar%==Success (
ECHO success
) ELSE (
ECHO failed
)

But more easily:
xcopy c:\file1 d:\file2
if ERRORLEVEL 1 (
echo failed>> c:\log.txt
) else (
echo success>> c:\log.txt
)
No need to set any variables.
 
Back
Top