"djc" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
|