Batch File Programming
Batch File Programming
*********************************
TWO MODES : INTERACTIVE MODE AND BATCH/SILENT MODE
IN INTERACIVE MODE : AS THE COMMAND IS TYPED IN THE PROMT ASKS FOR THE USER TO I
NTERACT IN THE BATCH MODE AFTER THE COMMAND IS TYPED IN THE USER IS NOT REQUIRED
EG :: DEL COMMAND
del a ;used for deleting the contents of a folder->once this command is typed in
it asks for a confirmation
del /q a ; here no confirmation is asked the '/q' switch runs the command in the
batch mode
when saving : save the file as a .bat extension from a notepad
two types of commands :: internal and external commands : internal -> commmands
which are default to all systems
and external -> commmands which are system specific
Batch Operators : Usual operators
Operator precedence : (),/,*,%,+,-
Sub commands and switches
eg : net users a a /add : here 'net' is the main command,'users' is the sub-comm
and,/add is the switch : basically the command adds a new user 'a' with a passwo
rd 'a'to the total users of the computer
COMMAND LIST
*****************
del :: commmad to delete the contents of a folder
/q : switch to run in batch mode
echo :: print the following command
pause :: to wait for the user's intervention at the end of the program
set :: for operations
/a : to do arithmetic operations such as addition etc - set /a 5+5 gives
10 as output
> :: Redirection of output
eg : echo hello > a.txt ; outputs hello to the text file a.txt ; NB : if a.
txt is not available, it creates it
~ :: Shortening of the path names : eg : documents folder can be represent
ed by docume~1 : NB : Apply '~' after 6 characters
&& :: Multiple command operation in a single line
| :: To give the output of one command as the input to another
eg : echo y | del *.txt ; gives a 'y' as confirmation whenever the del comm
and is called upon
help :: to get help
/? :: to get help on a specific command eg : net /? : gives help on a speci
fic command
REM :: For remarks
color :: for setting the color of the cmd display : eg :: color 1 2 :: first n
umber is the background color and the second one represents the foreground color