Command Prompt Chapter 6 Using DEL, DELTREE, RENAME …

Download Report

Transcript Command Prompt Chapter 6 Using DEL, DELTREE, RENAME …

Command Prompt
Chapter 10
Introduction to Batch Files
Richard Goldman
February 7, 2000
Batch File
• A batch file is an ASCII text file that contains a
list of commands that the operating system can
execute.
• A batch file must end with a .BAT extension.
• A batch file is run by entering its name at the
command prompt.
• A batch file may be interrupted by pressing
[Ctrl] + C
or
[Ctrl] +[Break].
Creating a Batch File
• Batch files can be written with any word
processor or editor that can save files in
ASCII text format.
• The MS DOS editor if often used while in
DOS for working with batch files.
• You may also use the
COPY CON [filename.bat]
to write simple BAT files.
Batch file Commands
• Call – Calls another batch file
• CHOICE – Pauses file and asks user to enter a
response to a question. (Not available in Win
2000)
• ECHO – Displays or hides text.
• FOR – Runs a command for files in a set.
• GOTO – Directs flow to specified label.
• IF – Conditional processing.
• PAUSE – Temporally stops processing.
• REM – Used to document batch file.
• SHIFT – Shifts replaceable parameters
REM Command
• Used to document a batch file.
• No action will be taken on lines that start
with a REM statement.
Replaceable Parameters
• Allows users to enter variables at the
command prompt that the batch file can
use.
• You can reference parameters 1-9
(0 is the position of the command).
• Substitute % followed by the entry order
number of the parameter.
• Example:
%3
AUTOEXEC.BAT File
• The AUTOEXEC.BAT file is automatically
run after the system is booted in Win 9X.
• Not used with NT Operating Systems.
• The system looks for it in the root
directory.
End