Saturday 2 March 2013

ECHO OFF

This Batch File deletes all unwanted Temporary files from your system
Now we go to the Windows\temp directory.
Invalid directory
Deleting unwanted temporary files...
File not found
Your System is Now Clean
Hey pretty good! But it still shows the initial ECHO OFF command. You
can prevent a particular command from being shown but still be
executed by preceding the command with a @ sign. So to hide even the
ECHO OFF command, simple replace the
first line of the batch file with @ECHO OFF
You might think that to display a blank line in the output screen you can
simply type ECHO by itself, but that doesn't work. The ECHO command
return whether the ECHO is ON or OFF. Say you have started your
batch file with the command ECHO OFF and then in the later line give
the command ECHO, then it will display ' ECHO is off ' on the screen.
You can display a blank line by giving the command ECHO.(ECHO followed
by a dot)Simply leaving a blank line in the code too displays a blank line
in the output.
You can turn ON the ECHO anytime by simply giving the command ECHO
ON. After turning the echo on , if you give the command ECHO then it
will return ' ECHO is on '
The PAUSE Command: Freezing Time
Say you create a batch file which shows the Directory Listing of a
particular folder(DIR) before performing some other task. Or
sometimes before deleting all files of a folder, you need to give the
user time to react and change his mind. PAUSE, the name says it all, it
is used to time out actions of a script.
Consider the following scenario:
REM This Batch program deletes *.doc files in the current folder.
REM But it gives the user to react and abort this process.
@ECHO OFF
ECHO WARNING: Going to delete all Microsoft Word Document
ECHO Press CTRL+C to abort or simply press a key to continue.
PAUSE
DEL *.doc
Now when you execute this batch program, we get the following output:
C:\WINDOWS>a.bat
WARNING: Going to delete all Microsoft Word Document
Press CTRL+C to abort or simply press a key to continue.
Press any key to continue . . .
The batch file program actually asks the user if he wishes to continue
and gives the user the option to abort the process. Pressing CTRL+C
cancels the batch file program(CTRL+C and CTRL+Break bring about the
same results)
^C
Terminate batch job (Y/N)?y
After this you will get the DOS prompt back.
****************

No comments:

Post a Comment