COPS 1103 4th Lesson - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

COPS 1103 4th Lesson

Description:

Part I Using DOS Commands and Creating a Batch File 45 minutes ... Choose one command (any of the remaining commands not used above) and document how you used it ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 22
Provided by: michael1021
Category:
Tags: 4th | cops | dos | lesson | setup

less

Transcript and Presenter's Notes

Title: COPS 1103 4th Lesson


1
COPS 1103 4th Lesson
  • Attendance
  • Quiz
  • Lecture
  • Lab
  • September 20 and 21st, 2004

2
Batch Files Defined
  • A batch file is a file containing DOS commands
    and/or other Batch Filenames that allows you to
    execute these commands automatically

3
Batch Files
  • Are productivity tools which reduce the number of
    keystrokes required to perform a task or series
    of tasks
  • Can contain commands all in a single file,
    executed when you run the Batch File

4
Batch File
  • When running a Batch File
  • Dos will run each of the commands in the file in
    sequence, just as if you had entered them at the
    keyboard
  • Example of a Batch File
  • AUTOEXEC.BAT

5
Purpose of a Batch File
  • Simplifies sequences of DOS commands
  • Eliminates Repetitive steps
  • Eliminates careless typing mistakes
  • Causes a sequence of DOS commands to be executed
    upon boot or reboot
  • Allows menus to be set up for easy start up of
    programs

6
Creating a Batch File
  • You may use any DOS commands in a Batch File
  • Lines are limited to 127 characters, anything
    beyond this amount is ignored
  • Regardless of the source of the Batch File, the
    outcome of its execution depends on the commands
    included in the file.

7
Creating Batch Files
  • Batch files must be created using a text editor
  • use something like notepad or EDIT.COM
  • dont use a word processor because special
    formatting characters are added that will cause
    your batch file to not execute properly.

8
Running a Batch File
  • Executed by entering the filename at the system
    prompt (remember PATH)
  • Terminate a Batch Command by pressing CTRL
    BREAK (found on the PAUSE key) or CTRL C. You may
    have to do this more than once for the program to
    be interrupted.

9
Batch File
  • Example of a batch file
  • This file is stored as MyBatch.BAT
  • REM This is my batch file
  • CLS
  • ECHO OFF
  • COPY MyFile.txt OldFile.txt
  • DEL MyFile.txt
  • You can store any commands in a batch
  • file.

10
Sample Batch File
  • ECHO OFF
  • ECHO Welcome to Durham College
  • ECHO
  • PAUSE
  • ECHO ON
  • DATE
  • TIME
  • CLS
  • PROMPT PG

11
Batch Commands
  • ECHO ON/OFF/message
  • ON commands in the batch file are displayed as
    they are executed
  • OFF commands in the batch file are not seen when
    executed
  • Message is displayed on the screen whether the
    ECHO command is ON or OFF. You may not set the
    ECHO on or off in a command that contains a
    message

12
Batch Commands
  • Pause causes the processing of a batch file to
    pause until a key is struck on the keyboard

13
Example of a BATCH FILE
  • COPY CON TEST1.BAT
  • ECHO OFF
  • CLS
  • ECHO This batch file will display the contents of
  • ECHO a DOS TEXT FILE
  • PAUSE
  • CLS
  • TYPE GREET.TXT
  • Rem you will need to create a GREET.TXT file

14
Batch Files
  • Part I Using DOS Commands and Creating a Batch
    File 45 minutes
  • -Create a new file called MyFirstBatchFile.bat.
  • -In the batch file, add the commands that will
    do the following-Create a directory called
    Lab2.
  • -Change to the Lab2 directory.
  • -Create a text file called ltyournamegt.txt.
    ltyournamegt first initial, last name
  • -Create a directory called OFiles.
  • -Copy ltyournamegt.txt to the OFiles directory.
  • -Rename the file in MyFiles to Rltyournamegt.txt
  • -Copy all DOS commands from the DOS directory
    that have a .com extension to the directory CDOS.
  • -List all files that start with s with a wide
    directory display, pausing when the screen is
    full
  • -Clear the screen and request the version of DOS.
  • -Test your batch file.
  • -Create a file called marks.txt that has all of
    the subjects that you are taking and the mark you
    would like to receive for each.
  • -Save the file.
  • -Request a screen listing of the file.
  • -Choose one command (any of the remaining
    commands not used above) and document how you
    used it
  • -Create a file called Inside.txt that is in a new
    directory called \New1\New2\New3.
  • -Move the file from that directory to another new
    directory called \New1\New4.

15
Replaceable Parameters
  • Placeholders that are typed in at the prompt
    after the name of the batch file
  • Numbered sequentially 1 to 9
  • First replaceable parameter is 1
  • 0 substitutes for the name of the batch command
    as typed in at the prompt

16
Example
  • EDIT MOVE.BAT
  • Copy 1 2
  • Del 1
  • When you run the batch file you need to type in
    the filename and destination after the batch
    filename
  • Example MOVE CFUN.BAT C\BATCH

17
Making Decisions
  • IF command required when you want a batch file
    command to be executed only when a condition is
    met
  • If the condition is not met then you my want to
    include a NOT in the command
  • Example IF 1 LOTUSc\lotus\lotus
  • Checks to see if the user had typed in Lotus and
    if so it would change to the Lotus directory and
    run the Lotus program

18
GOTO command
  • Allows you to switch to another part of the
    program by using a Label to direct it
  • The label appears on another line in the program
    and must be preceded by a colon (LABEL)
  • When the program switches to the label it then
    carries out the commands found there

19
Example
  • GOTO MESSAGE
  • DIR/W
  • MESSAGE
  • CLS
  • ECHO This is now a clean screen and is ready to go

20
Batch Files
  • Part II Modifying AUTOEXEC.BAT 45 minutes
  • - Set the prompt to display current directory
    and date.
  • -Set a path to include the DOS directory and the
    root of C
  • -Turn off the echo display
  • - Set up a little menu to display the following
  • -Start-up Program Menu Type the number of
    the program to run and press ENTER 1.
    WordStar 2. Lotus 1-2-3 3. Graphics
    program 4. No program

21
Batch File
  • PART 3
  • This Lab work is due at the end of the next Lab
  • -Research and create a batch file that will do
    the\
  • following
  • -ask the user for the day of the week
  • -if it is Mon, Wed or Fri
  • remove all files from the GONE directory
  • copy all files in the DAILY directory to the
    BACKUP directory
  • -if it is Tues or Thurs.
  • copy all files from the BACKUP directory to the
    GONE directory
  • copy all files in the DAILY directory to the
    BACKUP directory.
Write a Comment
User Comments (0)
About PowerShow.com