Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi all,
i have made a batch file which is working perfectly now.. but i don't know how to set ERROR CONTROL in this batch file can any one suggest me any ideas by how can i set error control.
here is the batch file
===========================================
@echo off
TITLE --- ONCOURSE UPLOADING ---::SET UP CURRENT DATE TO MMDDYYYY FORMAT
set Pdate=%date:~4,2%%date:~7,2%%date:~10,4%%1
COLOR 1f:: MAPPING SERVER PATH FOR DIRECT COPY
net use Z: \\server1\d$\test test@test1/USER:test.com\admn /PERSISTENT:YEScls
:: ASKING USER TO ENTER PREVIOUS DAY'S DATE
set /P d= PLEASE ENTER DATE : -::SET UP DESTINATION PATH WHERE ALL THE OPERATIONS WILL OCCUR
set e=D:\ONCOUR~1\AXA\Output\%d%::SET UP SYSTEMS XCOPY VARIABLE
set copyme=xcopy /s /c /d /e /h /i /r /yECHO.
IF /I %d% LSS %Pdate% GOTO DO
) ELSE
goto :error
):DO
Z:
CD Output\AXAHCF~1
%copyme% %d% %e% >> c:\ONCOUR~1\%d%_log.log
%copyme% %d%\*summary.txt c:\ONCOUR~1\axatemp
CLS
cd Z:\Output\AX15EC~1
%copyme% %d% %e% >> c:\ONCOUR~1\%d%_log.log
%copyme% %d%\*summary.txt c:\ONCOUR~1\axatemp
CLS
cd Z:\Output\AXAHCF~4
%copyme% %d% %e% >> c:\ONCOUR~1\%d%_log.log
%copyme% %d%\*summary.txt c:\ONCOUR~1\axatemp
CLS
cd Z:\Output\AXAUB9~3
%copyme% %d% %e% >> c:\ONCOUR~1\%d%_log.log
%copyme% %d%\*summary.txt c:\ONCOUR~1\axatemp
CLS
cd Z:\Output\AXAUB9~4
%copyme% %d% %e% >> c:\ONCOUR~1\%d%_log.log
%copyme% %d%\*summary.txt c:\ONCOUR~1\axatempCLS
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
COLOR 1f
CLS
echo -- PLEASE VERIFY THE SOURCE AND DESTINATION FILES IF NOT MATCHING PRESS CTRL+C --
echo.
echo.
echo - BELOW LISTED FILES HAVE BEEN COPIED -
echo -----------
echo.
echo LIST OF FILES FROM SOURCE LOCATION
echo.
echo.
:: VERIFYING SOURCE & DESTINATION TO CHECK ANY ERRORS AND COMPARE FILES
dir /B z:\Output\AXAHCF~1\%d%
dir /B z:\Output\AX15EC~1\%d%
dir /B z:\Output\AXAHCF~4\%d%
dir /B z:\Output\AXAUB9~3\%d%
dir /B z:\Output\AXAUB9~4\%d%
echo.
echo.
echo LIST OF FILES WHICH JUST COPIED ON ADMIN3
echo.
echo.
dir /B %e%
echo.
echo TOTAL FILES :
dir "%e%" /a-d /b/s |find /v /c "::"
echo.
echo.
ECHO PRESS ANY KEY TO OPEN THE SUMMARY FILES
pause>nul
CLS
echo (-- PLEASE COMPARE WITH E-MAIL --)
echo.
echo.
COLOR 1f
GOTO output
:output
@echo off
type c:\ONCOUR~1\axatemp\*summary.txt
ECHO.
echo.
echo.
echo PRESS ANY KEY TO UNZIP THE FILES AND MAKE IT READY TO UPLOAD
PAUSE>nul:: DELETING THE TEMPERORY FOLDER
rd /S /Q c:\ONCOUR~1\axatemp
CLS
COLOR EF
::MAKING A ZIP FILE IN SPECIFIED NAME AXA_<ENTERED DATE>.ZIP AND DELETING THE UNNECESSARY FILES
goto zip1
:zip1
"C:\Program Files\7-Zip\7z.exe" a -tzip "AXA_%d%.zip" -r "%e%\*" >> c:\ONCOUR~1\%d%_log.log
move /y *.ZIP %e% >> c:\ONCOUR~1\%d%_log.log
DEL /S /Q %e%\*.txt >> c:\ONCOUR~1\%d%_log.log
DEL /S /Q %e%\*.xls >> c:\ONCOUR~1\%d%_log.log
DEL /S /Q %e%\*.h* >> c:\ONCOUR~1\%d%_log.log
DEL /S /Q %e%\*.u* >> c:\ONCOUR~1\%d%_log.log
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
COLOR 1A
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo - OUTPUT HAS BEEN SUCCESSFULLY GENERATED -
echo -------------
PAUSE>nul
EXIT:error
CLS
COLOR 1A
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo --- THE %D% IS NOT ALLOWED ---
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo ---- PLEASE CONTACT SYSTEM ADMINISTRATOR----
echo.
pause>NUL
EXIT
=============================K2™
System/Network Engineer

What do you mean by "set error control"?
In a critical batch script you can check for the success of any command by inspecting the %ErrorLevel% system variable after the issued command, e.g.
copy .....
if errorlevel 1 <Command Failed: Do something>Beware the statement "if errorlevel #" is TRUE for ErrorLevel greater or equal the value coded, so in the previous example the statement following the If is executed for any errorlevel greater than 0 usually set for Success.
Many tools and utilities too set the errorlevel variable for execution checking.

thank you for you reply bro. but i m not getting much what are you saying. could you describe it with more details and any example or could you describe me various errorlevels if you can. thx
K2™
System/Network Engineer

A batch file consists of a number of commands, each of which may be tested for error level.
In your example:
::SET UP CURRENT DATE TO MMDDYYYY FORMAT
set Pdate=%date:~4,2%%date:~7,2%%date:~10,4%%1
COLOR 1fSET and COLOR are both commands, but of them only COLOR can be tested for errorlevel.
Nigel
This is just a sig

Stated that you do not explain what you are trying to achieve, there is no more to add what I said in my previous post to.
Each native batch command posts a return code into the ErrorLevel system variable that can be checked to examine the result of the action. The values set depend on the specific command, but usually 0 means the execution was succesful and greater codes show problems.
The statement "if ErrorLevel #" (with ErrorLevel NOT embraced by %) is used to perform the test and start subsequent actions. Beware the statement "if errorlevel #" is TRUE for ErrorLevel greater or equal the value coded.
So if you want to send a message if the Find command did not find the string "hello" code
find "hello" < myfile
if errorlevel 1 echo "hello" not foundor to check for a positive result
find "hello" < myfile
if not errorlevel 1 echo "hello" foundThe ErrorLevel variable can be also checked by coding
if %errorlevel% equ # (or geq, lss and so on...)
To know more about type if /? at prompt.
I hope this fits your needs.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |