Professional Documents
Culture Documents
CH 10 Power
CH 10 Power
Batch Files
Ch 10 1
Overview
Ch 10 3
Overview
Ch 10 4
Overview
Will write batch files using
replaceable parameters.
Ch 10 5
Overview
Learn how batch files can be
used from the desktop.
Ch 10 6
Concepts of Batch and
Interactive Processing
Batch file:
String together series of commands
executed sequentially with one command
without human interaction or interruption
Ch 10 7
Concepts of Batch and
Interactive Processing
Batch file:
Must be an ASCII file
Created with Edit, COPY CON, text editor,
or word processor which has “Save as text
file” option
Has .BAT or .CMD extension
Each line in batch file contains only one
command
Ch 10 8
Concepts of Batch and
Interactive Processing
Why batch files used:
Minimize keystrokes
Automate frequent/consistent
procedures
Do not need to interact with computer
while batch files are running
Ch 10 9
Concepts of Batch and
Interactive Processing
Batch processing:
Automate frequent/consistent
procedures
Batch files can be run at anytime
No user/computer interaction required
Ch 10 10
Concepts of Batch and
Interactive Processing
Interactive processing:
Also called online or real time mode
User interacts directly with computer
Information processed without delay
Ch 10 11
How Batch Files Work
Ch 10 12
How Batch Files Work
To locate file, operating system:
Looks internally for command
Using Extension Priority Rules,
searches on default drive and directory
Searches search path as set in PATH
statement following Priority Rules
Ch 10 13
How Batch Files Work
Table 10.1 Search Order for Extensions pp. 485-486
Ch 10 14
How Batch Files Work
Ch 10 15
How Batch Files Work
If file not found, get error message:
Ch 10 16
How Batch Files Work
Ch 10 17
Using EDIT to Write
Batch Files
Ch 10 18
Using EDIT to Write
Batch Files
Ch 10 19
Using EDIT to Write
Batch Files
Word-processing programs
can create text files if they
have a nondocument or text
mode.
Ch 10 20
Using EDIT to Write
Batch Files
EDIT:
Simple text editor in Command
Prompt window
Used to write batch files.
Ch 10 21
Using EDIT to Write
Batch Files
Notepad:
Window’s text editor
Used to write batch files
Ch 10 22
Activity—Writing and
Executing a Batch File
KEY CONCEPTS:
Create batch files with:
EDIT - tool to write batch files
Any text editor or word processor with
ASCII output
Batch file extensions - .BAT or .CMD
Execute the batch file the same ways as
you do any command
Ch 10 23
Writing and Executing a
Batch File to Save Keystrokes
Examples: DIR/AD
DIR/OS and DIR/O-S
Ch 10 24
Writing and Executing a
Batch File to Save Keystrokes
Ch 10 25
Writing and Executing a
Batch File to Save Keystrokes
Ch 10 27
Activity—Writing & Executing
a One-Letter Batch File
KEY CONCEPTS:
Pressing <F6> and <Enter> signals completion
<Ctrl> +Z same as pressing <F6>
Displaying file with TYPE indicates it is ASCII
file
Create one-line batch files
Directories have no size
Ch 10 28
Using Batch Files to Alter Your
Command Line Environment
Ch 10 29
Activity - Creating a Batch
File to Alter the Command
Line Session Environment
KEY CONCEPTS:
Created shortcut to open command line session
on desktop
Can decide what directory to be in
With /k parameter - include batch file that is
executed each time command line session opened
Value limited on floppy
Valuable on hard drive
Ch 10 30
Writing a Batch File to
Load Application Program
Ch 10 33
Creating Shortcuts for
Batch Files on the Desktop
Some things can be done with shortcut
that cannot do in the command line
interface.
Click shortcut to execute batch
Can change shortcut icon
Ch 10 34
Activity—Creating a
Shortcut on the Desktop
KEY CONCEPTS:
Clicking shortcut executes file
Can change icon so it is more
distinctive
Ch 10 35
Batch Files to Run
Windows Programs
Where Windows system files
reside will vary depending on
installation of Windows XP
Professional.
Ch 10 36
Batch Files to Run
Windows Programs
Windows “keeps notes” about itself in
system environment.
Path stored in environmental variable
%Path%
Drive referred to in environment as
%SystemDrive%
Directory where system files are located
referred to as %SystemRoot%
Ch 10 37
Batch Files to Run
Windows Programs
With Notepad:
Can create batch file that allows you
to run program without returning to
desktop
Can create log file that adds current
date and time to file created with
Notepad
Ch 10 38
Activity—Creating a Batch
File to Run Notepad
KEY CONCEPTS:
%SYSTEMROOT% (Environmental variable)
Windows knows where Windows files are located
and substitutes correct name
%% signs around name - OS substitutes value for
that variable.
Opened Notepad without returning to desktop
Used Notepad to create log file (case sensitive)
Created log file
Ch 10 39
Activity—Creating a Batch
File to Run Notepad
KEY CONCEPTS:
START command:
Can start a program in new window
while still executing batch program in
previous window
If title following command is in quotes,
will give window that title
Ch 10 40
Special Batch File Commands
Table 10.2 Batch File Commands pp.. 509-510
Ch 10 41
Special Batch File Commands
Table 10.2 Batch File Commands pp.. 509-510
Ch 10 42
The REM Command
Ch 10 44
Activity—Using REM
KEY CONCEPTS:
Used Edit to write batch file
Purpose of REM - provide explanatory
remarks about the batch file
If line begins with REM - explanatory text
follows and no action taken
No more lines in batch file -OS returns to
system level
Ch 10 45
The ECHO Command
ECHO ON command:
Displays command and the
command’s output to the screen
Is the default value
Ch 10 46
The ECHO Command
ECHO OFF command:
Minimizes screen clutter
User turns off display of command
then only see command’s output
Ch 10 47
The ECHO Command
Table 10.3 ECHO ON or OFF p. 512
Ch 10 48
Activity—Using ECHO
KEY CONCEPTS:
ECHO ON - see remarks and commands
ECHO OFF - output displayed not actual
commands
@ECHO OFF - @ suppresses display of
ECHO OFF
Purpose of batch files defeated if
interaction required by user
Ch 10 49
Activity—Using ECHO
Table 10.4 Echo On and ECHO Off: A Comparison of
Screen Displays p. 516
Ch 10 50
The CLS Command
CLS command used to clear
screen when it becomes full
of no longer needed
information.
Ch 10 51
Activity - Using CLS
KEY CONCEPTS:
After ECHO turned off screen
cleared
Ch 10 52
The PAUSE Command
PAUSE command instructs the
batch file to stop executing
until the user takes some
action.
Ch 10 53
Activity—Using Pause
KEY CONCEPTS:
Batch file “paused” - stopped
executing until some action is taken
Pause is not an order
Ch 10 54
Stopping a Batch File
from Executing
To interrupt a batch file during
execution:
Press <Ctrl> + C
Press <Ctrl> + <Break>
Ch 10 55
Stopping a Batch File
from Executing
Return to system prompt
when batch file interrupted.
Ch 10 56
Activity—Quitting a
Batch File
KEY CONCEPTS:
Results of Pressing <Ctrl> + C
Because of speed of computer difficult
to ascertain how many lines of batch
file read when <Ctrl> + C pressed
Ch 10 57
Replaceable Parameters
in Batch Files
Can use fixed or variable
parameters with batch files.
Ch 10 58
Replaceable Parameters
in Batch Files
Example of fixed parameter:
DIR A: /W
Examples of variable parameter:
TYPE THIS.FIL
TYPE TEST.TXT
Ch 10 59
Replaceable Parameters
in Batch Files
Ch 10 62
Replaceable Parameters
in Batch Files
Ch 10 63
Replaceable Parameters
in Batch Files
Ch 10 65
Multiple Replaceable
Parameters in Batch Files
Many commands used in
batch files may require
more than one parameter.
Ch 10 66
Multiple Replaceable
Parameters in Batch File
Ch 10 67
Multiple Replaceable
Parameters in Batch Files
Example:
COPY MYFILE.TXT YOUR.FIL
Ch 10 68
Activity—Using Multiple
Replaceable Parameters
KEY CONCEPTS:
Within batch files parameters do not
have to be in order.
Order used on command line
%1 - refers to first position after
command not first item on command
line
Ch 10 69
Activity—Using Multiple
Replaceable Parameters
Table 10.5 Positional Parameters p. 529
Ch 10 70
Activity—Using Multiple
Replaceable Parameters
KEY CONCEPTS:
Think of them as positional not replaceable
parameters
Copy files selectively (all except ones
hidden)
Do not use < > or | in batch files as OS
reads them as redirection or pipe symbols
Ch 10 71
Activity—Using Multiple
Replaceable Parameters
NOCOPY CLASS\*.ABC TRIP CLASS
Rest of lines executed in order
REM This batch file, NOCOPY.BAT,
will hide specified files,
REM then copy all other files from one
location to another,
Ch 10 72
Activity—Using Multiple
Replaceable Parameters
Ch 10 73
Creating Useful Batch Files
Ch 10 74
Activity—Writing Useful
Batch Files
KEY CONCEPTS:
Create batch file that will compare file
names in directories or on disks
Add @ECHO OFF at beginning of
batch file - see results of command not
REM statements
Ch 10 75
Activity—Writing Useful
Batch Files
Examine each part of command line:
Ch 10 76